Binding PHP to MySQL
The installation processes of PHP and MySQL occurs independent of each other. The operating system, in this case M.S. Windows, takes care of each installation process independent of the other. Hence when both products are installed one product really does not know that the other exists.
Since PHP application code will be required to access MySQL database resources, it’s necessary to inform PHP that MySQL exists. Informing PHP that MySQL exists and configuring PHP to connect to MySQL successfully is known as binding PHP to MySQL.
The following are the simple steps to be followed to connect PHP to MySQL.
The Binding Process:
In <driveletter>:\php locate a file named libmysql.dll.
NOTE: We have installed PHP in C:\, hence all further content will refer to C:\.
libmysql.dll was placed there during the installation process of PHP.
Copy and paste this file into C:\windows\system32.
Next in C:\php locate a file php.ini-recommended.
Copy and paste this file into C:\windows.
Rename the file php.ini-recommended to php.ini which in now within C:\windows.
Make the following changes in the php.ini file
Locate the extension_dir directive under Paths and Directories as shown in Diagram 1.
Change this to: extension_dir = “C:\php\ext”
NOTE: This directive needs to hold the path to where the ext folder exists within the PHP installation. Since PHP can be installed anywhere on the computer’s hard disk the value held in the extension_dir needs to be updated.
In the C:\windows\php.ini file locate the extension section, as shown in Diagram 2
Uncomment these 4 extensions, by deleting the ; at the start of the line.
NOTE: It’s a good idea to copy all four extensions to the very bottom of the extensions section and then uncomment them. This allows the extensions to be located quickly if they have to be commented again for any reason. These extensions are required by any internet application delivery framework. Please refer to Diagram 2.
The PHP extensions are:
|1||php_gd2.dll||Permits the compression of images prior their dispatch to a requesting Browser.|
|2||php_curl.dll||Required for URL redirection purposes, creating cookies and a ton of other stuff.|
|3||php_mysql.dll||Required for connecting to a MySQL db engine running in memory.|
|4||php_mysqli.dll||This is an updated PHP library required to connect to a MySQL db engine running in memory.
The php_mysqli.dll permits 30% to 40% faster data manipulation than mysql.dll.