Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 482
  • Last Modified:

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.
0
big3425
Asked:
big3425
  • 4
  • 3
  • 3
  • +4
6 Solutions
 
snoyes_jwCommented:
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:
<?php
mysql_connect("host", "user", "password") or die("Could not connect to server: " . mysql_error());
?>

Report here if all that went ok.
0
 
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??

Thanks.

Ray
0
 
psadacCommented:
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 (http://www.apachefriends.org/en/xampp.html)
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
big3425Author Commented:
Ok, it has the correct path.  Should I uninstall everything or just install the all in one? thanks.
0
 
Khanh DoanSenior DeveloperCommented:
Or you can use http://www.uniformserver.com/
You can start server when you want. It doesn't start at start up.
Bonmat86
0
 
mattjp88Commented:
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.

-Matt
0
 
Richard QuadlingSenior Software DeverloperCommented:
Normally all you need to do is make sure the mysql/bin directory is in the path as well as the PHP directory.

0
 
msimionCommented:
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
mircea
0
 
mattjp88Commented:
"somehow right"?  Why, am I known to be wrong all the time?
0
 
psadacCommented:
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.
0
 
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.
0
 
msimionCommented:
I am sorry mattjp88. I didn't mean to be rude. I cannot find the right words sometimes :)
You're the man.
0
 
msimionCommented:
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

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

http://www.wampserver.com/en/

-Matt
0
 
mattjp88Commented:
Sorry, forgot you got it working.  But if you want apache, that link should work for you.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 4
  • 3
  • 3
  • +4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now