Thursday, December 2, 2010

PHP and MySQL

In order for PHP to "connect" with MySQL, the mysqli extension must be enabled.

This can be done by running the configure script with a certain option. This must be done prior to building PHP.

For PHP 5.0, 5.1 and 5.2, the option is:
-with-mysqli=mysql_config_path/mysql_config. 
The mysql_config_path represents the location of the mysql_config program. The above option will enable mysqli and it will use the MySQL Client Library to communicate with the MySQL server.


For PHP 5.3.0 or newer, mysqli uses the MySQL Native Driver by default. For more information about MySQL Native Driver, click here.

How to use MySQL Native Driver with mysqli?
You need to configure the PHP source code using this option: --with-mysqli=mysqlnd

./configure --with-mysql=/usr/bin/mysql_config  \
--with-mysqli=mysqlnd \

If you do not know what ./configure is, do refer to my previous blog post here.
Currently, I am using PHP 5.3. You should see this in your phpinfo(), under configure command.

You can use mysqli in 2 forms. The first is object orientated and the second is procedural.
Do check this page for more information on the classes for mysqli.

Bravo! so now, we have connected PHP and MySQL! Next, I will move on to explain the fundamentals of MySQL first before we start to query the database. I will also start putting in some codes which I have done to share with everyone.

All the best and Happy coding!

PS: I love to learn new things, do drop me a msg if you have any programming problems to discuss!!

No comments:

Post a Comment