Fatal error: Call to undefined function mysql_connect() ...

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
SimonJ621
Forum Commoner
Posts: 36
Joined: Thu Jul 27, 2006 5:07 am
Location: Ohio

Fatal error: Call to undefined function mysql_connect() ...

Post by SimonJ621 »

Hello all,

I can't seem to get PHP to recognize MySQL. I know you are probably sick of hearing about this problem, but I haven't been able to find a solution. I have read through the documentation on the web including that which pertains to this error in these forums. I will attempt to outline the problem as detailed as possible:

PHP: 5.2.0RC2-dev
MySQL: 5.0

I am running a very simple test to determine if PHP will recognize MySQL.

Code: Select all

<?php

$conn = mysql_connect($hostname, $username, $password) or die("Unable to Connect to MySQL");

mysql_select_db("myputo", $conn) or die(mysql_error());

print "Connected to MySQL<br />";

mysql_close();

?>
Note that the variables are declared in the real version

And the result is:
Fatal error: Call to undefined function mysql_connect() ...

A snapshot of my phpinfo() can be found at: http://www.salzburgers.com/info.htm

I realize that MySQL is not in my phpinfo() and I am not sure why. extension=php_mysql.dll is uncommented, the correct path has been added to the environmental variable PATH, and php.ini is in C:\Windows and php_mysql.dll is in C:\Windows and C:\Windows\system32 (I read conflicting things).

http://www.salzburgers.com/phpini.htm has my php.ini info. I believe everything with this file is correct. There is one copy which resides on C:\Windows and there are three other files with the same name deep within the Zend Studio directory (one of them is blank, the other two only have a few dll locations for debugging in Zend Studio).

My environmental variables PATH has c:\php5, which is the directory where my php is installed. In the directory c:\php5\ext I have all relevant dll's including, libmysql.dll, libmysqli.dll, php_mysql.dll, and php_mysqli.dll. If I read correctly, the mysql and mysqli are the same file, but I have them both there anyways.

And if there is any other info I can give, pls let me know... I would think it should be as simple as uncommenting php_mysql.dll and making sure to have that in the correct directory.

If anyone could help, I would greatly appreciate it. I have been wasting my time here at work trying to get MySQL to work on my machine

Thank you,

Jason
User avatar
SimonJ621
Forum Commoner
Posts: 36
Joined: Thu Jul 27, 2006 5:07 am
Location: Ohio

Post by SimonJ621 »

Ok, still trying here...

I have noticed at least something that I am guessing is the cause of my problems. If a successful install shows the "Configuration File (php.ini) Path" as C:\WINDOWS\php.ini. (in the phpinfo()), then I am guessing that is where I am wrong, as mine only shows C:\WINDOWS. However, try as I may, I can't get this to function properly. My file settings for php.ini are now set to full control for every user group. Is there something else I can try?

Thanks,

Jason

note: I don't normally work with the networking side of things, so bare with me if my questions are basic...
jamiel
Forum Contributor
Posts: 276
Joined: Wed Feb 22, 2006 5:17 am
Location: London, United Kingdom

Post by jamiel »

Make sure the PHPINI directive is set in your Apache Config (Assuming Apache) and is pointing the the .ini file where you have made these changes.
User avatar
SimonJ621
Forum Commoner
Posts: 36
Joined: Thu Jul 27, 2006 5:07 am
Location: Ohio

Post by SimonJ621 »

Thanks Jamiel, that fixed the problem with reading the correct php.ini file. The new phpinfo() is now being displayed on the above link.

However, even though the right .ini file is being read, it still is not including the mysql libraries :/. Maybe something else needs to be changed with Apache? Would it be helpful to show my httpd.config (everything is used only locally)?

Thanks,

Jason
User avatar
SimonJ621
Forum Commoner
Posts: 36
Joined: Thu Jul 27, 2006 5:07 am
Location: Ohio

Post by SimonJ621 »

Ok, solved...

Thanks for all of your help. I downloaded the newest php5 version from the PHP website (not a snapshot) and also the newest dll's from the mysql website, re-compiled it all and it now works.

I originally was using a snapshot because I couldn't get php to work with apache. I think my problem had more to do with my httpd.config file than the php version. Anyways, it seems there was something not working correctly with the snapshot I was using.

Thanks for all the input. I know it's difficult to help solve a problem without actually being there.

Jason
DeodorantStick
Forum Newbie
Posts: 3
Joined: Sat Jul 29, 2006 9:54 am

MySQL Connect Error

Post by DeodorantStick »

Hi Everyone,

I'm currently having this same kind of problem. PHP5 works fine, except when I try to connect with MySQL. I get a "Fatal error: Call to undefined function mysql_connect()". I've scoured this forum and tried everything that people have suggested but haven't gotten far. Here is where I stand:

- I'm running IIS 5.1, PHP 5.1.4, and MySQL 5

- I've uncommented the lines for mysql and mysqli in my php.ini file
extension=php_mysql.dll
extension=php_mysqli.dll

- I've downloaded the latest versions of both .dll files from MySQL

- I've changed the extension directory in my php.ini file and moved all of the .dll extensions to this directory.
extension_dir = "D:/php"

- I've deleted all other instances of the php.ini file and have added my php directory to the windows path variable. It shows up on the phpinfo() screen as "D:\php\"

- I've given IUSR_COMPUTERNAME permission to read and execute all contents of my php directory, including the .dll files

-I've checked my phpinfo() and it shows that neither mysql.dll has been loaded.

Usually, I never have to post in a forum, but this one has got me completely baffled.

Any ideas?

Thanks
User avatar
SimonJ621
Forum Commoner
Posts: 36
Joined: Thu Jul 27, 2006 5:07 am
Location: Ohio

Post by SimonJ621 »

When you look at your phpinfo(), does it display your php.ini directory something like this:

C:\WINDOWS\php.ini

If you don't have the \php.ini on the end, then your file isn't being read.

Also, I don't know much about the IIS installation but you may need to add PHPRC to your environmental variables that points to the file that has your php.ini file (e.g. C:\WINDOWS)

Jason
DeodorantStick
Forum Newbie
Posts: 3
Joined: Sat Jul 29, 2006 9:54 am

Post by DeodorantStick »

Here is the exact line from the phpinfo() screen

Configuration File (php.ini) Path D:\WINDOWS

Where would I change this?

The correct path to my php.ini is D:\PHP\php.ini
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

DeodorantStick wrote:The correct path to my php.ini is D:\PHP\php.ini
That's maybe the one you want to change but it's obviously not the one used by your php installation.
http://de2.php.net/ini explains when and where php looks for ini files
DeodorantStick
Forum Newbie
Posts: 3
Joined: Sat Jul 29, 2006 9:54 am

Post by DeodorantStick »

Fixed it, thanks guys. Volka, that link really helped out.

The problem was that my PHP instalation wasn't finding my php.ini file.

The solution was to add a PHPRC environmental variable that pointed to my php.ini file.

This link here will explain how to add a PHPRC environmental variable for WindowsXP:
http://forums.mysql.com/read.php?52,69846,83144
User avatar
SimonJ621
Forum Commoner
Posts: 36
Joined: Thu Jul 27, 2006 5:07 am
Location: Ohio

Post by SimonJ621 »

Glad it's working now :)

Happy PHPing

Jason
Post Reply