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:


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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.