Index: phpdoc/en/faq/databases.xml diff -u phpdoc/en/faq/databases.xml:1.9 phpdoc/en/faq/databases.xml:1.10 --- phpdoc/en/faq/databases.xml:1.9 Sun Oct 14 06:26:19 2001 +++ phpdoc/en/faq/databases.xml Sun Oct 14 07:55:30 2001 @@ -1,8 +1,8 @@ - + - Connecting to databases - Connecting to databases + Database issues + Database issues This section holds common questions about relation between @@ -193,6 +193,38 @@ or recompile from the source rpm and remove the switch in the spec file that turns on the threaded client code. Either of these suggestions will fix this. Then recompile PHP with the new MySQL libs. + + + + + + + + Why do I get an error that looks something like this: + "Warning: 0 is not a MySQL result index in <file> + on line <x>" or "Warning: Supplied argument is not + a valid MySQL result resource in <file> on line <x>? + + + + + You are trying to use a result identifier that is 0. The 0 indicates + that your query failed for some reason. You need to check for errors + after submitting a query and before you attempt to use the returned + result identifier. The proper way to do this is with code similar + to the following: + +$result = mysql_query("SELECT * FROM tables_priv"); +if (!$result) { + echo mysql_error(); + exit; +} + + or + +$result = mysql_query("SELECT * FROM tables_priv") + or die("Bad query: ".mysql_error()); + Index: phpdoc/en/faq/general.xml diff -u phpdoc/en/faq/general.xml:1.10 phpdoc/en/faq/general.xml:1.11 --- phpdoc/en/faq/general.xml:1.10 Fri Sep 21 18:47:31 2001 +++ phpdoc/en/faq/general.xml Sun Oct 14 07:55:30 2001 @@ -1,13 +1,13 @@ - + General Information General Information - - This section holds the most general questions about PHP: - what it is and what it does. - + + This section holds the most general questions about PHP: + what it is and what it does. + @@ -16,7 +16,7 @@ - From the manual: + From the preface of the manual: PHP is an HTML-embedded scripting language. Much of @@ -34,7 +34,7 @@ - What is the relation between the versions ? + What is the relation between the versions? @@ -97,6 +97,26 @@ Please see the What's new in PHP4 overview for a detailed explanation of these features and more. + + + + + + + + I think I found a bug! Who should I tell? + + + + + You should go to the PHP Bug Database and make sure the bug + isn't a known bug. If you don't see it in the database, use + the reporting form to report the bug. It is important to use + the bug database instead of just sending an email to one of the + mailing lists because the bug will have a tracking number assigned + and it will then be possible for you to go back later and check + on the status of the bug. The bug database can be found at + &faqurl.php.bugs;. Index: phpdoc/en/faq/html.xml diff -u phpdoc/en/faq/html.xml:1.5 phpdoc/en/faq/html.xml:1.6 --- phpdoc/en/faq/html.xml:1.5 Sun Oct 14 06:41:34 2001 +++ phpdoc/en/faq/html.xml Sun Oct 14 07:55:30 2001 @@ -1,5 +1,5 @@ - + PHP and HTML PHP and HTML @@ -10,6 +10,35 @@ + + + + I'm trying to use an <input type="image"> tag, but + the $foo.x and $foo.y variables aren't available. + Where are they? + + + + + When submitting a form, it is possible to use an image instead of + the standard submit button with a tag like: + + +]]> + + When the user clicks somewhere on the image, the accompanying form + will be transmitted to the server with two additional variables: + foo.x and foo.y. + + + Because $foo.x and $foo.y are invalid variable names in PHP, they are + automagically converted to $foo_x and $foo_y. That is, the periods + are replaced with underscores. + + + + How do I create arrays in a HTML <form>? @@ -60,6 +89,58 @@ + + + + How do I get all the results from a select multiple HTML tag? + + + + + The select multiple tag in an HTML construct allows users to + select multiple items from a list. These items are then passed + to the action handler for the form. The problem is that they + are all passed with the same widget name. ie. + + +]]> + + Each selected option will arrive at the action handler as: + +var=option1 +var=option2 +var=option3 + + Each option will overwrite the contents of the previous + $var variable. The solution is to use + PHP's "array from form element" feature. The following + should be used: + + +]]> + + This tells PHP to treat $var as an array and + each assignment of a value to var[] adds an item to the array. + The first item becomes $var[0], the next + $var[1], etc. The count + function can be used to determine how many options were selected, + and the sort function can be used to sort + the option array if necessary. + + + Note that if you are using JavaScript the [] + on the element name might cause you problems when you try to + refer to the element by name. Use it's numerical form element + id instead, or enclose the variable name in single quotes and + use that as the index to the elements array, for example: + +variable = documents.forms[0].elements['var[]']; + + + + Index: phpdoc/en/faq/installation.xml diff -u phpdoc/en/faq/installation.xml:1.8 phpdoc/en/faq/installation.xml:1.9 --- phpdoc/en/faq/installation.xml:1.8 Sun Oct 14 05:16:30 2001 +++ phpdoc/en/faq/installation.xml Sun Oct 14 07:55:30 2001 @@ -1,5 +1,5 @@ - + Installation Installation @@ -45,6 +45,81 @@ + + + + Unix: I installed PHP, but every time I load a document, I get the + message 'Document Contains No Data'! What's going on here? + + + + + This probably means that PHP is having some sort of problem + and is core-dumping. Look in your server error log to see if + this is the case, and then try to reproduce the problem with + a small test case. If you know how to use 'gdb', it is very + helpful when you can provide a backtrace with your bug report + to help the developers pinpoint the problem. If you are using + PHP as an Apache module try something like: + + + + Stop your httpd processes + + + + + gdb httpd + + + + + Stop your httpd processes + + + + + > run -X -f /path/to/httpd.conf + + + + + Then fetch the URL causing the problem with your browser + + + + + > run -X -f /path/to/httpd.conf + + + + + If you are getting a core dump, gdb should inform you of this now + + + + + type: bt + + + + + You should include your backtrace in your bug report. This should be submitted to + &faqurl.php.bugs; + + + + + + If your script uses the regular expression functions + (ereg and friends), you should make sure + that you compiled PHP and Apache with the same regular + expression package. This should happen automatically with + PHP and Apache 1.3.x + + + + @@ -177,6 +252,24 @@ + + + + Unix: I patched Apache with the FrontPage extensions patch, and + suddenly PHP stopped working. Is PHP incompatible with the + Apache FrontPage extensions? + + + + + No, PHP works fine with the FrontPage extensions. The problem + is that the FrontPage patch modifies several Apache structures, + that PHP relies on. Recompiling PHP (using 'make clean ; make') + after the FP patch is applied would solve the problem. + + + + @@ -277,6 +370,26 @@ + + + + + Windows: I've followed all the instructions, but still can't + get PHP and IIS to work together! + + + + + Make sure any user who needs to run a PHP script has the rights + to run php.exe! IIS uses an anonymous user + which is added at the time IIS is installed. This user needs + rights to php.exe. Also, any authenticated + user will also need rights to execute php.exe. + And for IIS4 you need to tell it that PHP is a script engine. + + + + Index: phpdoc/en/faq/languages.xml diff -u phpdoc/en/faq/languages.xml:1.6 phpdoc/en/faq/languages.xml:1.7 --- phpdoc/en/faq/languages.xml:1.6 Fri Sep 21 18:47:31 2001 +++ phpdoc/en/faq/languages.xml Sun Oct 14 07:55:30 2001 @@ -1,13 +1,13 @@ - + PHP and other languages PHP and other languages - - PHP is the best language for Webbing, but what about - other languages? - + + PHP is the best language for web programing, + but what about other languages? + @@ -17,23 +17,26 @@ ASP is not really a language in itself, it's an acronym for Active - Server Pages, the actual language used to program ASP with is a - script version of Visual Basic. The biggest drawback of ASP is that + Server Pages, the actual language used to program ASP with is Visual + Basic Script or JScript. The biggest drawback of ASP is that it's a proprietary system that is natively used only on Microsoft Internet Information Server (IIS). This limits it's availability to Win32 based servers. There are a couple of projects in the works - that allows ASP to run in other environments and webservers; + that allows ASP to run in other environments and webservers: InstantASP from Halcyon (commercial), Chili!Soft ASP from Chili!Soft - (commercial) and OpenASP from ActiveScripting.org - (free). ASP is said to be a slower + (commercial) and OpenASP from + ActiveScripting.org (free). ASP is said to be a slower and more cumbersome language than PHP, less stable as well. Some of - the pros of ASP is that since it uses VBScript it's relatively easy - to pick up the language if you're already know how to program in - Visual Basic. ASP support is also enabled by default in the IIS - server making it easy to get up and running. + the pros of ASP is that since it primarily uses VBScript it's + relatively easy to pick up the language if you're already know + how to program in Visual Basic. ASP support is also enabled by + default in the IIS server making it easy to get up and running. + The components built in ASP are really limited, so if you + need to use "advanced" features like interacting with FTP servers, + you need to buy additional components. @@ -44,8 +47,8 @@ - Yes, asp2php is the one most often - referred to. + Yes, asp2php is + the one most often referred to. @@ -60,14 +63,15 @@ programming tasks and trying out new ideas. PHP is generally referred to as more stable and less resource intensive as well. Cold Fusion has better error handling, database abstraction and date parsing - although database abstraction is being addressed in PHP 4. Another + although database abstraction is addressed in PHP 4. Another thing that is listed as one of Cold Fusion's strengths is its excellent search engine, but it has been mentioned that a search engine is not something that should be included in a web scripting language. PHP runs on almost every platform there is; Cold Fusion is only available - on Win32, Solaris, Linux and HP/UX. Cold Fusion has a better IDE + on Win32, Solaris, Linux and HP/UX. Cold Fusion has a good IDE and is generally easier to get started with, whereas PHP initially - requires more programming knowledge. + requires more programming knowledge. Cold Fusion is designed with + non-programmers in mind, while PHP is focused on programmers. A great summary by Michael J Sheldon on this topic has @@ -88,9 +92,9 @@ because of this get very complicated. The flexibility / complexity of Perl makes it easier to write code that another author / coder has a hard time reading. PHP has a less confusing and stricter format - without losing flexibility. PHP is easier to integrate into existing + without losing flexibility. PHP is easier to integrate into existing HTML than Perl. PHP has pretty much all the 'good' functionality of - Perl; constructs, syntax and so on, without making it as complicated + Perl: constructs, syntax and so on, without making it as complicated as Perl can be. Perl is a very tried and true language, it's been around since the late eighties, but PHP is maturing very quickly. Index: phpdoc/en/faq/migration.xml diff -u phpdoc/en/faq/migration.xml:1.6 phpdoc/en/faq/migration.xml:1.7 --- phpdoc/en/faq/migration.xml:1.6 Fri Sep 21 18:47:31 2001 +++ phpdoc/en/faq/migration.xml Sun Oct 14 07:55:30 2001 @@ -1,26 +1,32 @@ - + Migrating from PHP 2 to PHP 3 Migrating from PHP 2 to PHP 3 - - PHP has already a long history behind him : - Legendary PHP 1.0, PHP/FI, PHP 3.0 and PHP/Zend 4.0. - + + PHP has already a long history behind him: + Legendary PHP 1.0, PHP/FI, PHP 3.0 and PHP 4.0. + - Migrating from PHP2 to PHP3? + Migrating from PHP 2 to PHP 3? PHP/FI 2.0 is no longer supported. Please see - the manual for - information about migration from PHP/FI 2.0. + appropriate manual + section for information about migration + from PHP/FI 2.0. + + + If you are still working with PHP 2, we + strongly recommend you + to upgrade straight to PHP 4. Index: phpdoc/en/faq/migration4.xml diff -u phpdoc/en/faq/migration4.xml:1.5 phpdoc/en/faq/migration4.xml:1.6 --- phpdoc/en/faq/migration4.xml:1.5 Fri Sep 21 18:47:31 2001 +++ phpdoc/en/faq/migration4.xml Sun Oct 14 07:55:30 2001 @@ -1,19 +1,19 @@ - + Migrating from PHP 3 to PHP 4 Migrating from PHP 3 to PHP 4 - - PHP has already a long history behind him : - Legendary PHP 1.0, PHP/FI, PHP 3.0 and PHP/Zend 4.0. - + + PHP has already a long history behind him : + Legendary PHP 1.0, PHP/FI, PHP 3.0 and PHP 4.0. + - Migrating from PHP3 to PHP4 + Migrating from PHP3 to PHP4 @@ -23,13 +23,17 @@ process. If you're really unsure about compatibility you should install PHP 4 in a test environment and run your scripts there. + + Also see the appropriate migration + appendix of this manual. + - Incompatibles functions? + Incompatible functions? Index: phpdoc/en/faq/using.xml diff -u phpdoc/en/faq/using.xml:1.8 phpdoc/en/faq/using.xml:1.9 --- phpdoc/en/faq/using.xml:1.8 Wed Oct 3 15:16:08 2001 +++ phpdoc/en/faq/using.xml Sun Oct 14 07:55:30 2001 @@ -1,13 +1,13 @@ - + Using PHP Using PHP - - This section gathers most common errors that occur at - build time. - + + This section gathers most common errors you can + face, while writing PHP scripts. + @@ -19,19 +19,20 @@ - Make sure that the track_vars feature is - enabled in your php3.ini file. If you compiled PHP with - "--enable-track-vars" it will be on by default. - Alternatively you can enable it at run-time on a per-script - basis by putting <?php_track_vars?> at the top of your file. - When track_vars is on, it creates three associative arrays. - $HTTP_GET_VARS, $HTTP_POST_VARS and $HTTP_COOKIE_VARS. So, to - write a generic script to handle POST method variables you would + Make sure that the track_vars + feature is enabled in your php.ini + file. Since PHP 4.0.3, this feature is always on. When + track_vars is on, it creates some + associative arrays, the most important here is: + $HTTP_POST_VARS. So, to write a generic + script to handle POST method variables you would need something similar to the following: - while (list($var, $value) = each($HTTP_POST_VARS)) { - echo "$var = $value<br>\n"; - } + $value) { + echo "$var = $value
\n"; +} +]]>
@@ -47,8 +48,8 @@ - First off, take a look at the addslashes() - function. It will do exactly what you want. You should also have + First off, take a look at the addslashes + function. It will do exactly what you want. You should also have a look at the magic_quotes_gpc directive in your php.ini file. @@ -61,11 +62,12 @@ When I do the following, the output is printed in the wrong order: - function myfunc($argument) { - echo $argument + 10; - } - $variable = 10; - echo "myfunc($variable) = " . myfunc($variable); +function myfunc($argument) +{ + echo $argument + 10; +} +$variable = 10; +echo "myfunc($variable) = " . myfunc($variable); what's going on? @@ -84,19 +86,24 @@ Hey, what happened to my newlines? - -<PRE> - 1 <?echo $result[1];?> - 2 <?echo $result[2];?> - + + + + + +]]> + In PHP, the ending for a block of code is either "?>" or - "?>\n" (where \n means a newline). This means that you need to - insert an extra newline after each block of PHP code in the above - example. + "?>\n" (where \n means a newline). So in the example above, + the echoed sentences will be on one line, because PHP ommits + the newlines after the block ending. This means that you need to + insert an extra newline after each block of PHP code to make + it print out one newline. Why does PHP do this? Because when formatting normal HTML, this @@ -117,14 +124,16 @@ The getallheaders function will do this if - you are running PHP as a module. So, the following bit of code - will show you all the request headers: - - $headers = getallheaders(); - for(reset($headers); $key = key($headers); next($headers)) { - echo "headers[$key] = ".$headers[$key]."<br>\n"; - } - + you are running PHP as an Apache module. So, the following bit + of code will show you all the request headers: + + $content) { + echo "headers[$name] = $content
\n"; +} +]]> +
@@ -137,34 +146,15 @@ - The security model of IIS is at fault here. This is a problem - common to all CGI programs running under IIS. A workaround is - to create a plain HTML file (not parsed by php) as the entry page - into an authenticated directory. Then use a META tag to redirect - to the PHP page, or have a link to the PHP page. PHP will - then recognize the authentication correctly. When the ISAPI - module is ready, this will no longer be a problem. This should - not effect other NT web servers. For more information, see: - &faqurl.iis;. - - -
- - - - - I've followed all the instructions, but still can't - get PHP and IIS to work together! - - - - - Make sure any user who needs to run a PHP script has the rights - to run php.exe! IIS uses an anonymous user which is added at the - time IIS is installed. This user needs rights to php.exe. - Also, any authenticated user will also need rights to execute - php.exe. And for IIS4 you need to tell it - that PHP is a script engine. + The security model of IIS is at fault here. This is a problem + common to all CGI programs running under IIS. A workaround is + to create a plain HTML file (not parsed by PHP) as the entry page + into an authenticated directory. Then use a META tag to redirect + to the PHP page, or have a link to the PHP page. PHP will + then recognize the authentication correctly. With the ISAPI + module, this is not a problem. This should not effect other + NT web servers. For more information, see: + &faqurl.iis;. @@ -179,19 +169,19 @@ - Very good question! ;) This is a tricky little issue and it has come up - twice in the past month as of this writing. Both times I ended up + Very good question! ;) This is a tricky little issue and it has come up + twice in the past month as of this writing. Both times I ended up spending a good 20 minutes trying to figure out what the heck was going - on. The answer is that both IE and Lynx ignore any NULs - (\0) in the HTML stream. Netscape does not. + on. The answer is that both IE and Lynx ignore any NULs + (\0) in the HTML stream. Netscape does not. The best way to check for this is to compile the command-line version of PHP (also known as the CGI version) and run your script from the command line and pipe it through 'od -c' and look for any - \0 characters. (If you are on Windows you need to + \0 characters. (If you are on Windows you need to find an editor or some other program that lets you look at binary files) When Netscape sees a NUL in a file it will typically not output - anything else on that line whereas both IE and Lynx will. If this - issue has bitten you, congratulations! You are not alone. + anything else on that line whereas both IE and Lynx will. If this + issue has bitten you, congratulations! You are not alone. @@ -205,11 +195,11 @@ - You need to turn off the short tags by setting short_tags to 0 in your - php.ini file, or by using the php3_short_tags Apache - directive. (You could even use a <File> section to do this - selectively.) You can also disable and re-enable the short tags - in your script using the short_tags() function. + You need to turn off the short tags by setting + short_tags to 0 in your + php.ini file, or by using the appropriate + Apache directive. You could even use a <File> section to + do this selectively. @@ -217,18 +207,19 @@ - How can I use PHP with FrontPage or Dreamweaver or some - other HTML editor that insists on moving my code around? + How can I use PHP with FrontPage or some other HTML editor + that insists on moving my code around? One of the easiest things to do is to enable using ASP tags in your PHP code. This allows you to use the ASP-style <% and %> code - delimiters. Most of the popular HTML editors handle those more + delimiters. Some of the popular HTML editors handle those more intelligently (for now). To enable the ASP-style tags, you need - to set the asp_tags php.ini variable, or use the - asp_tags Apache directive. + to set the asp_tags + php.ini variable, or use the + appropriate Apache directive. @@ -242,120 +233,34 @@ - The best way is to stick a <?phpinfo()?> tag on a page and - load it up. This will show you all sorts of information about your - PHP setup, including a list of both environment variables and also - special variables set by your web server. This list can't really be - documented in the PHP documentation because it will change from one - server to another. - - - - - - - - Why do I get an error that looks something like this: - "Warning: 0 is not a MySQL result index in <file> - on line <x>" or "Warning: Supplied argument is not - a valid MySQL result resource in <file> on line <x>? - - - - - You are trying to use a result identifier that is 0. The 0 indicates - that your query failed for some reason. You need to check for errors - after submitting a query and before you attempt to use the returned - result identifier. The proper way to do this is with code similar - to the following: - - $result = mysql_query("select * from tables_priv"); - if(!$result) { - echo mysql_error(); - exit; - } - - or - - $result = mysql_query("select * from tables_priv") - or die("Bad query: ".mysql_error()); - + The best way is to stick a <?php phpinfo(); ?> + part on a page and load it up. This will show you all sorts of + information about your PHP setup, including a list of both + environment variables and also special variables set by your + web server. This list can't really be documented in the PHP + documentation because it will change from one server to another. - + - I'm trying to use an <input type="image"> tag, but - the $foo.x and $foo.y variables aren't available. - Where are they? + I'm trying to access one of the standard CGI + variables (such as $DOCUMENT_ROOT or $HTTP_REFERER) in a user-defined + function, and it can't seem to find it. What's wrong? - When submitting a form, it is possible to use an image instead of - the standard submit button with a tag like: - -<input type="image" SRC="image.gif" NAME="foo"> - - When the user clicks somewhere on the image, the accompanying form - will be transmitted to the server with two additional variables: - foo.x and foo.y. - - - Because $foo.x and $foo.y are invalid variable names in PHP, they are - automagically converted to $foo_x and $foo_y. That is, the periods - are replaced with underscores. + Environment variables are normal global variables, so you must + either declare them as global variables in your function (by using + "global $DOCUMENT_ROOT;", for example) or by using + the global variable array (ie, "$GLOBALS["DOCUMENT_ROOT"]". - - - - How do I get all the results from a SELECT MULTIPLE HTML tag? - - - - - The SELECT MULTIPLE tag in an HTML construct allows users to select multiple - items from a list. These items are then passed to the action handler for the - form. The problem is that they are all passed with the same widget name. ie. - - <SELECT NAME="var" MULTIPLE> - - Each selected option will arrive at the action handler as: - - var=option1 - var=option2 - var=option3 - - Each option will overwrite the contents of the previous $var variable. The - solution is to use PHP's - non-indexed array feature. The following should be used: - -<SELECT NAME="var[]" MULTIPLE> - - This tells PHP to treat var as an array and each assignment of a - value to var[] adds an item to the array. The first item becomes - $var[0], the next $var[1], etc. - The count function can be used to determine how - many options were selected, and the sort function can be - used to sort the option array if necessary. - - - Note that if you are using JavaScript the [] on the element name - might cause you problems when you try to refer to the element by name. - Use it's numerical form element id instead, or enclose the - variable name in single quotes and use that as the index to the - elements array, for example: - -variable = documents.forms[0].elements['var[]']; - - - -