PHP 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
anointing
Forum Newbie
Posts: 8
Joined: Wed Jun 18, 2008 10:01 am

PHP Fatal Error: Call to Undefined Function mysql_connect()

Post by anointing »

Hi

I'm running Apache 2.2.8 on Windows XP with Php 5.2.5 and Mysql 6.0. When I run a simple php script (test.php) to connect to a mysql database and retrieve data, I get this:

Fatal error: Call to undefined function mysql_connect()

I know it is because Php cannot locate the mysql library so as adviced on the net I set the following as follows:

1. update php.ini file in my C:/windows folder as follows:
;extension_dir = "./" ===> extension_dir = "C:/php/ext"
2. set the environment system : path= C:/php

The php_mssql.dll is located in C:/php/ext and the libmysql.dll driver is in C:/php so both should be found by the php engine. However, When I try to connect to mysl using php
(from test.php) I still get the same error call:
Fatal error: Call to undefined function mysql_connect()
Meanwhile I am able to update my database using command line calls to mysql. So clearly the fault lies with my Php set up.

The test.php script is as follows:
----------------------------------
<?php
$dbcnx = mysql_connect('localhost', 'root', 'root');
mysql_select_db('1jdb', $dbcnx);
$result = mysql_query('SELECT joketext from joke');
while($row = mysql_fetch_array($result));
{
echo '<p>' . $row['jokedate'] . '</p><br />';
}
?>
---------------------------------------

PLEASE ADVICE

Thanks
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: PHP Fatal Error: Call to Undefined Function mysql_connect()

Post by jaoudestudios »

it sounds like the mysql library is not installed or activated.

Create a new php file and put this code in it and run the file through apache.
<?php
echo phpinfo();
?>

This will display a page with your apache setup. A very useful tool to see which libraries are installed and what settings you have.

Post back with the result from the php file.
anointing
Forum Newbie
Posts: 8
Joined: Wed Jun 18, 2008 10:01 am

Re: PHP Fatal Error: Call to Undefined Function mysql_connect()

Post by anointing »

Hi

I'm assuming that the mysql libraries required by php 5.0+ are located within the \php\ext folder and other executables within \php\

I've tested for presence of mysql libraries using the following script:
<?php
echo phpinfo();
?>

The only reference I found was in the PATH, pointing to executable files in the mysql folder:
C:\Program Files\MySQL\MySQL Server 6.0\bin

I updated the extension_dir from "C:/php/ext" to "C:\php\ext" because I could not remember wheher the slashes should be leading or trailing lol - anyway, it made no difference. I have since reverted back to "C:/php/ext" which I think is the correct protocol in windows.

I then placed copies of libmysql.dll and php_mysql.dll drivers in the C:\windows\system32 folder and rebooted Windows XP: but it still made no difference.

I still have an earlier version of Apache Tomcat 4.1.24 still installed as a standalone servlet engine for testing java servlets and jsps. I was wondering whether this might interfere with the latest version of Apache I have installed: Apache 2.2; although I very much doubt it.

Please let me know what you think.

Thanks
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: PHP Fatal Error: Call to Undefined Function mysql_connect()

Post by jaoudestudios »

hi

What port does your Apache tomcat use? when I use to use WAMP many years ago I found that skype interfered with apache as it used the same port! port 80. So I could never run both at the same time until I change the port on apache. Then in my browser I has to use http://localhost:port/ or http://ip:port/ for remote access on my network.

Sorry that I am not much more help. I am more rusty than I thought on windows apache. But I do highly recommend wamp http://www.en.wampserver.com/ as it was very easy to use.

On windows apache (wamp) it does not matter if you use / or \ for the path as windows accepts both. When coding use / otherwise when you upload it to your server which is probably linux it wont work.
anointing
Forum Newbie
Posts: 8
Joined: Wed Jun 18, 2008 10:01 am

Re: PHP Fatal Error: Call to Undefined Function mysql_connect()

Post by anointing »

Hi,

I don't think it's a port issue. I finally seem to have resolved the issue now.

I noticed the extension_dir variable in phpinfo() indicates it is still looking under the default php setting of c:\php5, instead of c:\php\ext. I then moved the php.ini file from C:\windows to c:\php. On calling my original php file to connect to mysql, the error flag disappeared:
Fatal Error: Call to Undefined Function mysql_connect().

This type of issue can give a guy sleepless nights lol. I ACTUALLY RESOLVED THIS AFTER GETTING UP HALF WAY THROUGH THE NIGHT. The important thing is that php can now find the mysql libraries and "talk" to mysql.

Although the error is no longer being flagged, I wonder if this is just a temporary patch of sorts? Should the php.ini not be in c:\windows? I think placing all the drivers and the php.ini within the php folder makes for cleaner upgrades and uninstalling. So I wont need to look for the old php.ini file somewhere in my C drive a couple of years later when I upgrade.

Thanks for your help guys. I now want to implement a database driven shopping cart using php and mysql. No doubt I'll be calling on you for further assistance.

Thanks and g/night to you all.
nullpointer
Forum Newbie
Posts: 1
Joined: Sun Aug 24, 2008 11:31 am

Re: PHP Fatal Error: Call to Undefined Function mysql_connect()

Post by nullpointer »

r u still looking for the answer to this one? i can give u if you want...
linhmai
Forum Newbie
Posts: 1
Joined: Tue Sep 02, 2008 7:28 pm

Re: PHP Fatal Error: Call to Undefined Function mysql_connect()

Post by linhmai »

Hi,
I have the same problem. My php.ini is in c:\php and I changed extension_dir = 'c:\php\ext', but in my phpinfo() details, it still says extension_dir = c\php5\.
eddy147
Forum Newbie
Posts: 1
Joined: Sat Sep 20, 2008 4:47 am

Re: PHP Fatal Error: Call to Undefined Function mysql_connect()

Post by eddy147 »

Hi anointing,
I've had exactly the same problem, and your solution, putting the php.ini in your php install dir (c:\php) instead of windows system dir (c:\WINDOWS), helped, finally. after days.

Thank you, thank you.

Note.
Why oh why is this not documented?
sequimboy
Forum Newbie
Posts: 2
Joined: Thu Nov 20, 2008 8:22 pm

Re: PHP Fatal Error: Call to Undefined Function mysql_connect()

Post by sequimboy »

Thanks for your posting. I just had the same problem however my solution is slightly different for PHP Version 5.2.6 which I just installed today. After reading the php.ini I notice in C:/php/ that there were two php.ini files. One that was php.ini-recommended and one php.ini-dist. I decided to take the recommendation and changed it to php.ini. Now I have a new set of errors but that is progress.

Thanks!

Sequimboy
sequimboy
Forum Newbie
Posts: 2
Joined: Thu Nov 20, 2008 8:22 pm

Re: PHP Fatal Error: Call to Undefined Function mysql_connect()

Post by sequimboy »

I finally had to locate and move php.ini from the Windows folder to get the site to work. In fact I didn't have it on the machine I was working on so I got if from another machine. Renaming php.ini-recommended didn't work. It just stopped without an error message.

What a hassle.

Sequimboy
isralennon
Forum Newbie
Posts: 2
Joined: Thu Nov 27, 2008 6:14 pm

Re: PHP Fatal Error: Call to Undefined Function mysql_connect()

Post by isralennon »

Hi there.

I tried all your suggestions exactly to the same problem, but it still doesn't work. :banghead: I still have the flag Fatal error: Call to undefined function mysql_connect(). Other PHP commands work well, so I think PHP is installed ok (What would I be missing?)

This is what I have observed.
1- There were the original 2 files: php.ini-recomended and php.ini-dist. I decided to use the dist file because of the debugging options.
2- I edited my D:\PHP\php.ini file (cause I installed it on D, where my current Windows XP is installed) and I realized no changes were made on my site no matter what I changed! Then I searched my computer for php.ini file and I found out there the php.ini file on D:\Windows. I edited this one and I could see changes at last, but still had the error message.

3. I decided to move the php.ini file to my D:\php folder (renaming the original php.ini file, so I don't lose it. anyway it was the php.ini-dist file) and I got a big sorprise! My site was still working, but it was not reading my php.ini file anymore! I realized this cause when I executed the line phpinfo() it still said I was using the file at D:\Windows, however it said that it could not load it, so I believe it was loading some default settings inside the dll of PHP. It looks something like this:

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

and when the php.ini file was at Windows directory, it was something like this:

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

4. I renamed my php.ini file at D:\PHP so there was no php.ini file at all anywhere in my computer just to verify my theory... and PHP still worked (after I stopped and restarted the service... I even restarted the computer)

So... any suggestions? Is there a way to tell the PHP dll to use my D:\PHP\php.ini file instead of D:\Windows\php.ini file so I can test the upper solution?

Thanks a lot for your attention and your patience!

:?:
isralennon
Forum Newbie
Posts: 2
Joined: Thu Nov 27, 2008 6:14 pm

Re: PHP Fatal Error: Call to Undefined Function mysql_connect()

Post by isralennon »

Hi there again...
:D
I kept searching the web for answers, and I found that somebody with this problem moved all of the DLLs from C:\PHP folder to c:\Windows\System32. I did that and it worked!

I moved all the dlls from my D:\PHP folder to my D:\Windows\System32 folder and the error message wasn't there anymore! It was not necessary to move my D:\PHP\ext directory. I edited the D:\Windows\PHP.ini file to set the extensions_dir variable to D:\PHP\ext and it seems to be working well.

I hope this helps somebody if all of the other solutions didn't. Thanx everybody for sharing your knowledge and experience.

However, I still wonder... why it is not documented at installation file? How can we get it to be there at the FAQ section?

Regards. :drunk:

isralennon.
Post Reply