MySQL Forums
Forum List  »  PHP

Re: Fatal error: Call to undefined function mysql_connect()
Posted by: Mel Peterson
Date: August 10, 2007 08:40AM

I just spent the better part of a day digging through these threads to resolve this issue. Finally found all the answers I needed, but it was such a chore, I thought a short summary might help others move a little more quickly through the process.

I probably shouldn't post this. I really have no idea what I am talking about. But these steps worked for me.

This summary refers to a Windows system running Apache 2.2, php 5.2.3, and MySQL 5.0


1. Check you System Path

Make sure your system path includes your php and mySQL/bin directories. In my case, these were: c:\php and c:\program files\mysql\mysql server 5.0\bin. It apparently helps if the php directory comes before the mysql/bin directory.

2. Configure the path to php.ini in Apache

Somewhere in Apache's httpd.conf file , there is a PHPIniDir line. Find it and make sure that it reads: PHPIniDir "C:/php" (See point 3e below.)

3. Set up php.ini.

Look for the following lines (a., b., c., & d.) in your php.ini file and edit them accordingly

a. doc_root = [your server document path]

In my case, this was: c:\apache software foundation\apache2.2\htdocs ; Yours may be different, but just make sure the document root here is the same as in Apache's httpd.conf file.

b. session.save_path = c:/temp ;

Don't know what this line does. Just saw somewhere that it was necessary. The above line worked for me, but I think you can use any directory you want. Just make sure it exists.

c. extension_dir = "c:\php\ext"

This line tells php where to look for extension. I gather that the above is the default for php5. For php4, I think it may be c:\php\extensions. But just make sure that this line matches wherever all your php extension dll files are located.

d. Uncomment or add the following lines in the extension section of the php.ini file. They load the extensions.

extension=php_mysql.dll
extension=php_mysqli.dll 

e. Save php.ini to c:\php.

Actually, I have seen documentation that says you should save it to your system root directory i.e. c:\windows. But saving in c:\php worked for me. If you save it somewhere other than c:\php, just make sure the PHPIniDIr line in Apache's httpd.conf file matches the location. (This was the issue that screwed me up the longest. Apparently, Apache really has to know where to find the php.ini file.)

4. MySQL has its own builds of libmysql.dll, php_mysql.dll and php_mysqli.dll. They call the collection Connector/PHP. You can download the Connector/PHP zips from http://dev.mysql.com/downloads/connector/php/.

a. There are two connector downloads, one for MySQL and one for MySQLi. If you get both, after you unzip, you will have all three files.

b. Copy libmysql.dll to your php directory (probably c:\php?)

c. Copy php_mysql.dll and php_mysqli.dll to c:\php\ext or wherever your extension files go.

5. Finally, make sure that you only have one copy of libmysql.dll, php_mysql.dll, php_mysqli.dll in your system path. If you have multiple copies of these dll files, it can apparently cause problems.

6. Restart your server and run a phpinfo() script. If you have sections for MySQL and MySQLi, success!

Hope this doesn't hurt anyone.

Options: ReplyQuote


Subject
Written By
Posted
Re: Fatal error: Call to undefined function mysql_connect()
August 10, 2007 08:40AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.