Configure MySQL & PHP in Windows

from the Artful MySQL Tips List


Put extension DLL's in an extension directory. Placing them in the Windows directory will only create a mess. Edit php.ini to point to the extension direction.

Drop to DOS and go to your php executable directory; type php -v. If you don't receive an error then PHP is reading your extension meaning your php.ini is configured correctly.

Then run

<?php
mysqli_connect
('HOST','USR','PWD''test' ) or die(mysqli_error());
?>


Save it as connect.php in your PHP directory. Drop to DOS and run:

<?php
php connect
.php
?>


You need not run it in the PHP directory or bin if you have your PHP executable directory in your windows environment path, which is good to do in general.

If you don't get an error but you do in Apache, update the MySQL PHP Connector by downloading the correct version from

https://www.tutorialspoint.com/mysqli/mysqli_installation.htm.

Make sure you obtain the correct connector for your version of MySQL.

Rename your old DLL's and drop the new connector dll's in their respective directories. Run the test in DOS again to make sure they work. If so, try it in apache next. Generally, if the script works in DOS but not apache, the PHP connector is not correct.

Note: You only need your DLL's in one location. Avoid having multiple copies of the DLL's all over the place. If you have programming experience or upgraded DLL dependent applications, then you'll understand, again good practice.

This will usually happen if you don't have a clean install. I've also seen PHP packages that didn't include older MySQL connectors, so if you're running say a 4.X of MySQL you may see the error as well.

If you still get an error in Apache, triple check your httpd.conf file, there really isn't much to getting PHP working with it. And double check that you did download the right connector dll.

After you gain some experience you may want to look into more recent extensions and improved connection methods but most people stick with the stock setup. Anything more is best left to the hard core PHP community that compiles their own binaries.

Paraphrased from:
Scott Hiser
Toledo, OH
Technology Advisor

Last updated 27 Feb 2017


Return to the Artful MySQL Tips page