PHP Knowledge Base Update -- August 6th, 1999

From: Date: Sat, 07 Aug 1999 06:56:14 +0000
Subject: PHP Knowledge Base Update -- August 6th, 1999
Groups: php.kb 
Request: Send a blank email to php-kb+get-21@lists.php.net to get a copy of this message
Now that the PHPKB has grown to a considerable size I am finding less new material on the mailing list each day. So I've added a new section at the bottom of these mail outs which lists 5 entries chosen at random from the knowledge base. Hopefully this will help new members see older material and keep known solutions fresh in our minds. Cheers, Nathan ------------------------------------------------------------ Which tags should I use, <?php ?> or <? ?>? http://e-gineer.com/e-gineer/phpkb/view.phtml/qid/548 ------------------------------------------------------------ John Coggeshall Both sets of tags will work. <?php has the advantage that it cannot be disabled. ------------------------------------------------------------ What does the error "Failed to load resource DLL odbcint.dll" mean? http://e-gineer.com/e-gineer/phpkb/view.phtml/qid/549 ------------------------------------------------------------ Brad Marsh Do you have ODBC installed? If you don't have MS Office 97 already, you can get MS ODBC from the Microsoft web site... Here's what the MS web site (http://support.microsoft.com/search/default.asp - I searched for "Microsoft ODBC") says: "Support Downloads File Title: Microsoft ODBC Drivers for 32-Bit Programs File Name: GE1263.EXE File Size: 2804116 bytes File Date: 04/18/96 Keywords: APPNOTE ODBC ORACLE SQL Jet Access FoxPro dBASE Paradox Excel Word C++ VB Basic Description: Contains Microsoft ODBC drivers for 32-bit ODBC- compliant programs running under Windows 95 or Windows NT. NOTE: If you are using Microsoft Office 97, you do not need this Application Note. The Data Access Pack is located in the Valupack\Dataacc folder on the Microsoft Office 97 compact disc. More Information about GE1263.EXE" And here's the URL for the file: http://support.microsoft.com/download/support/msfiles/GE1263.exe ------------------------------------------------------------ How can I make columns in MySQL case sensitive? http://e-gineer.com/e-gineer/phpkb/view.phtml/qid/550 ------------------------------------------------------------ Adam Whitehead Use the BINARY keyword on each column you want to be case sensitive. ie. COLUMN_X CHAR(128) BINARY NOT NULL Then it will use case sensitive searches and selects. It is important to note that even if a column doesn't include the BINARY keyword, all data is still stored in the correct case. ************************************************************ RANDOMLY SELECTED PHPKB ENTRIES ************************************************************ ------------------------------------------------------------ How can I check the size of a file on the client side? How can I limit the size of files uploaded to the server by a user? http://e-gineer.com/e-gineer/phpkb/view.phtml/qid/410 ------------------------------------------------------------ Javascript does not allow operations on files, and so it is not possible to check the size of a file on the client side. Most people checking the size of a file will want to do so before the user uploads the file to their server. You cannot actually do this until the file upload is in progress. You can put a MAXFILESIZE HTML tag in the <INPUT TYPE="file"> tag... Or you can check the filesize once it's uploaded to PHP and simply not process the upload if it's too big or too small (the file will be automatically deleted after your script exits).... ------------------------------------------------------------ http://e-gineer.com/e-gineer/phpkb/view.phtml/qid/410 ------------------------------------------------------------ Javascript does not allow operations on files, and so it is not possible to check the size of a file on the client side. Most people checking the size of a file will want to do so before the user uploads the file to their server. You cannot actually do this until the file upload is in progress. You can put a MAXFILESIZE HTML tag in the <INPUT TYPE="file"> tag... Or you can check the filesize once it's uploaded to PHP and simply not process the upload if it's too big or too small (the file will be automatically deleted after your script exits).... ------------------------------------------------------------ How do I run PHP from the command line or as a shell script? http://e-gineer.com/e-gineer/phpkb/view.phtml/qid/12 ------------------------------------------------------------ Install PHP in CGI mode. You can of course have both (CGI and module) on the same system. When you get there, php -h gives you the command line parameters you may find useful. And you can use the !# construction to cause the script to load php. The syntax is: #!/path/to/php <?php // your php code ?> and if you want to stop it from sending the CGI-style headers, do: #!/path/to/php -q <?php // your php code ?> On a win32 system, just cd to the dir that the script is in and type the script name: C:\>myscript.php Note, however, that if the script is a form that posts back to itself, the only thing you will get is the form elements echoed to the console. You will have to hardcode the form field values first if you want to see the post in action. Also, the .php extension should be registered to be executed with php.exe ------------------------------------------------------------ Are static variables preserved across queries to PHP? http://e-gineer.com/e-gineer/phpkb/view.phtml/qid/127 ------------------------------------------------------------ No. Every request to PHP is executed completely independently. Static variables are static only for the current request. If you want to store data across requests you need to use files, a database or shared memory. http://www.php.net/manual/variables.php3 PHPLIB is a great place to start if you are trying to create sessions on your site and store data across requests. http://phplib.shonline.de/ ------------------------------------------------------------ How can I fetch the field name and data for every row of a database query result? How can I get the column (field) name from a database query result row in MySQL? http://e-gineer.com/e-gineer/phpkb/view.phtml/qid/348 ------------------------------------------------------------ To work with fields in MySQL you need to know about the following functions: http://www.php.net/manual/function.mysql-num-fields.php3 http://www.php.net/manual/function.mysql-field-name.php3 Here is an example that will print the field names and their values from each row in a MySQL query result: <?php $dbh = mysql_connect("host", "foo1", "foo2"); mysql_select_db("foo3"); $query = "select * from foo"; $result = mysql_query($query, $dbh); $fields = mysql_num_fields($result); while ($row=mysql_fetch_array($result)) { for ($i=0; $i<$fields; $i++) { $name=mysql_field_name($result, $i); echo "$name = $row[$name]<BR>\n"; } echo "<br><br>\n"; } <? Should give you output like this: field1 = id1 field2 = blahblah field3 = done field1 = id2 field2 = blah field3 = doneagain (etc)

« previous php.kb (#21) next »