Need help with getting PHP5 to connect to MySQL.

Help me  -  Help me

I can't seem to get PHP to connect to MySQL through even a simple script.  I have a box running xp and a box running win2k and both will not connect.  My xp box gets the "undefined function" and nothing happens at all with my win2k box.

Here is what I have done so far:
1. Installed both PHP, MySQL, and a web server
2. I installed PHP with the windows installer, then I also downloaded the zip file for php and unzipped it into the PHP folder.
3. I am using Macromedia Dreamweaver as my development program.
4. I have successfully executed the standard Hello World.php with my web server so I know PHP is working.
5. I deleted the php.ini file on my win2k box in the winnt folder and added to my windows PATH the c:\PHP folder.
6. I went into my php.ini file in my PHP folder and took out the ";" in front of the extension for mysql.

I have a simple database query that connects or dies, then creates a database.  I don't get any errors when I execute this file, but when I go into mysql, the database has been created.  Help Please.
Who is Participating?
snoyes_jwConnect With a Mentor Commented:
Did you restart the web server after editing php.ini?

First step is to confirm that MySQL is enabled.

Write a script that contains just the following:
<?php phpinfo(); ?>
When you load that in your browser, you should find a section called MySQL.  If it is not there, PHP has not been set up to use MySQL.

If MySQL is enabled, run the following:
mysql_connect("host", "user", "password") or die("Could not connect to server: " . mysql_error());

Report here if all that went ok.
big3425Author Commented:
Ok, I rebooted the machine and did your script.  I do have a MySQL section.  But, now I am getting the error connecting to mysql.  this is definately the farthest I have gone.  so what now??


psadacConnect With a Mentor Commented:
additionally your phpinfo page should display your "Configuration File (php.ini)". If this is not the "c:\PHP" folder, then add the following line in your httpd.conf :

PHPIniDir "C:/php"

if nothing works, try a all-in-one package : xampp for example (
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

big3425Author Commented:
Ok, it has the correct path.  Should I uninstall everything or just install the all in one? thanks.
Khanh DoanConnect With a Mentor Senior DeveloperCommented:
Or you can use
You can start server when you want. It doesn't start at start up.
mattjp88Connect With a Mentor Commented:
I had a lot of trouble getting php5 to work with mysql.  there are a number of files that need to be moved from a folder within your php directory to either the main php directory, or to the system32 folder.  I'm not sure which ones, but try moving mysqllib.dll and/or mysl.dll to the main php directory and see if it works.  When starting apache, does a dos window open and display some text?  I know mine does running on a 2k box.  Check and see if you can catch if there is an error being displayed in that.  If you can't catch it, or you don't get that dos window.  Open a dox prompt (Start->run "cmd" or "command") and then navigate to your apache 'bin' directory I believe.  it should have apache.exe in it.  once there from within the dos window, type "apache.exe" and hit enter.  Have Apache shut down prior to this point.  See what message it displays to you when starting.  It should say something like "can't load mysqlxxxxx.dll library" or something of the sort.  That will narrow down your search for the missing file.

Richard QuadlingConnect With a Mentor Senior Software DeveloperCommented:
Normally all you need to do is make sure the mysql/bin directory is in the path as well as the PHP directory.

msimionConnect With a Mentor Commented:
mattjp88 is somehow right. you will have to move libmysql.dll from php dir into windir\system32 or windir. try both, but restart apache after every combination. don't forget to uncomment the mysql extension in php.ini. the simplest thing is to create a test.php file which would contain <?php phpinfo(); ?>. When running test.php you should see the mysql extension among many others...

If still having troubles let us know...g'luck
"somehow right"?  Why, am I known to be wrong all the time?
RQualding is rgiht, all you need is to have mysql/bin and php directory in your path. If you copy any dll in your system32, windir or whatever, you will get unpredictable results when you will upgrade php or mysql.
big3425Author Commented:
Thanks to all of you.  I have definately been struggling with this setup, but now I have finally gotten it to connect.  Now I can go and learn and build my website.  Thanks.

Here is what got me to the solution.

First of all, I wasn't rebooting after making changes.
But, after installing, these are the actual modifications I made:

1. I had to use Abyss Web Server, because I couldn't get Apache configured correctly.
2. Then I had to unzip the full PHP package into my PHP folder.
3. Then I had to add the PHP and MySQL folders to the windows PATH
4. Then I changed the php.ini file - uncommented the mysql extension and put localhost in and also the default port of 3306.
5. Then I rebooted - it worked after that.  Thanks guys.
I am sorry mattjp88. I didn't mean to be rude. I cannot find the right words sometimes :)
You're the man.
big3425  - Follow the install.txt file from the php directory. It is not quite necessary to reboot the computer. If any error messages paste them on google. You will finally manage to get apache/php/mysql talking to eachother

If you want it working right now, here is a package that installs apache/php/mysql all together, preconfigured to work together.

Sorry, forgot you got it working.  But if you want apache, that link should work for you.
All Courses

From novice to tech pro — start learning today.