2.7. Activating MySQL Support

The basic PHP software consists of a core set of functionality and optional extensions that provide additional functionality. MySQL support is provided by extensions. In PHP 4, MySQL support is provided by default, but beginning with PHP 5.0, you must activate MySQL support before PHP can interact with MySQL databases. (For more information about PHP extensions, see Book V.)

PHP provides two extensions for MySQL support: the mysql extension and the mysqli (MySQL Improved) extension. Which extension you need to activate depends on which version of PHP and MySQL you're using. The mysql extension, available with PHP 4, 5, and 6, provides functions for interacting with MySQL version 4.0 and earlier. The mysqli extension, added in PHP 5, provides functions for interacting with MySQL version 4.1 and later. You can also use the mysql functions with the later versions of MySQL, but they can't access some of the new features added in the later versions of MySQL.

2.7.1. Activating MySQL support on Linux and the Mac OS

MySQL support is activated during PHP installation on Linux and Mac with installation options. The installation options to activate MySQL must be used during Step 4 of the installation to activate MySQL support. MySQL support can't be added later, after PHP is compiled and installed.

Use one of the following installation options:

--with-mysqli=DIR
--with-mysql=DIR

DIR is the path to the appropriate MySQL directory. When using with-mysqli, use ...

Get PHP & MySQL® Web Development All-in-One Desk Reference for Dummies® now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.