Solved

Need help with getting PHP5 to connect to MySQL.

Posted on 2006-06-28
15
472 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Normally all you need to do is make sure the mysql/bin directory is in the path as well as the PHP directory.

0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 3

Assisted Solution

by:msimion
msimion earned 80 total points
Comment Utility
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
Comment Utility
"somehow right"?  Why, am I known to be wrong all the time?
0
 
LVL 14

Expert Comment

by:psadac
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
Sorry, forgot you got it working.  But if you want apache, that link should work for you.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Router for PHP reqeusts 12 29
Mail Not Sent 6 41
Need some help setting up PDFLib 4 24
php documentation 4 19
Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

772 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