24.4. API PHP de MySQL

MySQL 5.0

24.4. API PHP de MySQL

PHP is a server-side, HTML-embedded scripting language that may be used to create dynamic Web pages. It is available for most operating systems and Web servers, and can access most common databases, including MySQL. PHP may be run as a separate program or compiled as a module for use with the Apache Web server.

PHP actually provides two different MySQL API extensions:

  • mysql - Available for PHP versions 4 and 5, this extension is intended for use with MySQL versions prior to MySQL 4.1. This extension does not support the improved authentication protocol used in MySQL 4.1.1 and later, nor does it support prepared statements or multiple statements. If you wish to use this extension with MySQL 4.1 and more recent versions of MySQL, you will likely want to configure the MySQL server to use the --old-passwords option (see Sección A.2.3, “). This extension is documented on the PHP Website at http://php.net/mysql.

  • mysqli - Stands for "MySQL, Improved", this extension is available only in PHP 5. It is intended for use with MySQL 4.1.1 and later. This extension fully supports the authentication protocol used in MySQL 4.1.1 and subsequent MySQL releases as well as the Prepared Statements and Multiple Statements APIs. In addition, this extension provides an advanced, object-oriented programming interface. You can read the documentation for the mysqli extension at http://php.net/mysqli. A helpful article can be found at http://www.zend.com/php5/articles/php5-mysqli.php.

The PHP distribution and documentation are available from the PHP Website.

24.4.1. Problemas comunes con MySQL y PHP

  • Error: "Maximum Execution Time Exceeded" This is a PHP limit; go into the file and set the maximum execution time up from 30 seconds to something higher, as needed. It is also not a bad idea to double the RAM allowed per script to 16MB instead of 8MB.

  • Error: "Fatal error: Call to unsupported or undefined function mysql_connect() in .." This means that your PHP version isn't compiled with MySQL support. You can either compile a dynamic MySQL module and load it into PHP or recompile PHP with built-in MySQL support. This is described in detail in the PHP manual.

  • Error: "undefined reference to `uncompress'" This means that the client library is compiled with support for a compressed client/server protocol. The fix is to add last when linking with .

  • Error: "Client does not support authentication protocol" This is most often encountered when trying to use the older mysql extension with MySQL 4.1.1 and later. Possible solutions are: downgrade to MySQL 4.0; switch to PHP 5 and the newer mysqli extension; or configure the MySQL server with . (See Sección A.2.3, “, for more information.)