Solved

Need help with getting PHP5 to connect to MySQL.

Posted on 2006-06-28
15
473 Views
Last Modified: 2013-12-12
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
Comment
Question by:big3425
  • 4
  • 3
  • 3
  • +4
15 Comments
 
LVL 33

Accepted Solution

by:
snoyes_jw earned 100 total points
ID: 17004525
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
 

Author Comment

by:big3425
ID: 17005560
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
 
LVL 14

Assisted Solution

by:psadac
psadac earned 80 total points
ID: 17005582
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
 

Author Comment

by:big3425
ID: 17005627
Ok, it has the correct path.  Should I uninstall everything or just install the all in one? thanks.
0
 
LVL 10

Assisted Solution

by:Khanh Doan
Khanh Doan earned 80 total points
ID: 17006613
Or you can use http://www.uniformserver.com/
You can start server when you want. It doesn't start at start up.
Bonmat86
0
 
LVL 6

Assisted Solution

by:mattjp88
mattjp88 earned 80 total points
ID: 17006899
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
 
LVL 40

Assisted Solution

by:RQuadling
RQuadling earned 80 total points
ID: 17007330
Normally all you need to do is make sure the mysql/bin directory is in the path as well as the PHP directory.

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 3

Assisted Solution

by:msimion
msimion earned 80 total points
ID: 17008907
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
 
LVL 6

Expert Comment

by:mattjp88
ID: 17012580
"somehow right"?  Why, am I known to be wrong all the time?
0
 
LVL 14

Expert Comment

by:psadac
ID: 17013118
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
 

Author Comment

by:big3425
ID: 17014883
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
 
LVL 3

Expert Comment

by:msimion
ID: 17015718
I am sorry mattjp88. I didn't mean to be rude. I cannot find the right words sometimes :)
You're the man.
0
 
LVL 3

Expert Comment

by:msimion
ID: 17015729
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
 
LVL 6

Expert Comment

by:mattjp88
ID: 17017909
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
 
LVL 6

Expert Comment

by:mattjp88
ID: 17017919
Sorry, forgot you got it working.  But if you want apache, that link should work for you.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now