DelphiFAQ Home Search:

Fatal error: Call to undefined function: mysql_connect()

 

comments45 comments. Current rating: 5 stars (13 votes). Leave comments and/ or rate it.

Question:

I install Apache, php 4.1.2 and mysql on RedHat Linux. When calling a php script that connects to the mysql database, I get this error message:

Fatal error: Call to undefined function: mysql_connect()
in /var/www/html/buyersguides/global/system_globals.inc on line 12


Answer:

Most likely mysql is not enabled on your php installation. You configured this when you compiled the php sources.

Create a dummy HTML page on your web server with the php code from below and call it through the web browser. It will tell you if mysql is enabled. (If you do not see a table with parameters for mysql, then mysql is not enabled in your php build.)

How do I enable mysql in my php installation?

If you have an RPM based system like Mandrake, then you need to install package php-mysql-4.3.2-3mdk.i586.rpm. You may need to resolve the requirement of libmysql12 - these are shared libraries needed to dynamically load and use MySQL.

Visit libmysql on rpmfind.net and get the RPM there.

Install it all then with and restart Apache:

[root]#ls *.rpm

   -rw-r--r--  1 nobody nogroup  22333 Jul 26  2004 php-mysql-4.3.2-3mdk.i586.rpm
   -rwxr--r--  1 nobody nogroup 263560 Aug  9 10:55 libmysql12-4.0.23-2mdk.i586.rpm

[root]#rpm --install libmysql12-4.0.23-2mdk.i586.rpm

   warning: libmysql12-4.0.23-2mdk.i586.rpm: V3 DSA signature: NOKEY, key ID 70771ff3


[root]#rpm --install php-mysql-4.3.2-3mdk.i586.rpm

   warning: php-mysql-4.3.2-3mdk.i586.rpm: V3 DSA signature: NOKEY, key ID 70771ff3

[root]#apachectl -k restart

On a system that is not based on RPM installation you need to go to your php installer directory and call configure to create a new make file, then recompile:


# ./configure --with-apxs=/usr/local/apache/bin/apxs --with-mysql=/usr/local/mysql
# make
# make install
At the end do not forget to restart Apache.

<?php
  echo phpinfo();
?>

Content-type: text/html

Comments:

You are on page 1 of 3, other pages: [1] 2 3
2005-11-15, 05:50:44
anonymous from United Kingdom  
phpinof() - does not show mysql as being activated.
php -i (from the command line) shows mysql as being activated.

I am using php 5 on a windows (2000) platform - through IIS (php5isapi.dll)
2005-11-15, 05:54:39
kaisa_ho@hotmail.com from United Kingdom  
phpinof() - does not show mysql as being activated.
php -i (from the command line) shows mysql as being activated.

using iis (php5isapi.dll) on a windows 2000 platform.

have tried everything that is available on all sites/forums.

i.e.,
extension=php_mysql.dll (removed comments)
doc_root ='c:\testsite'
extension_dir = 'C:\PHPext'

still keep getting this error:

Fatal error: Call to undefined function mysql_connect()

can you help?
2006-01-15, 17:34:59
anonymous from Belarus  
Hello everybody!

I've finally got solved the splinter for me!
Here are the steps to get rid of it.

What I did first was reinstalling php by a new way.
I have zipped version of php-5.0.2-Win32. I created a new folder php on c: disk and put all the

unzziped files into it.

I deleted files I had copied before from C:\windows\system32.
libmysql.dll
libmysqli.dll
php5apache2.dll
php5apache.dll
php5ts.dll
php_mysql.dll

In the Next step I opened a config. file 'httpd.conf' for apache (i have ver.2.0.52) and added

this content into the bottom of the page.

LoadModule php5_module 'c:/php/php5apache2.dll'
AddType application/x-httpd-php .php
PHPIniDir 'C:/php'

1-st line indicates where the module needed for apache to load php is located
2-nd line indicates the type of php script whether it php or php3 e.t.c
3-d line indicates where your php.ini file is located (the path where apache is have to look for

it)

Saved and close it.
Restarted the apache.

After that I went to c:\php, located 'php.ini-recommended' file, made a copy of it and renamed

the original one into php.ini.

Since now my php started to work, but without mysql.

In the next step, I opened php.ini file, found a line extension_dir = './' and changed it for

extension_dir = 'C:\php\ext' (to find it fast, press ctrl+f on your keyboard, make sure you have

clicked your mouse at the start of the page, to make it search from the top.).
Then I found a line ;extension=php_mysql.dll and removed the semicolon in the begining.
Saved the document.

Restarted the apache.

After all, I ran the test.php file and finally got Mysql info.
If you already got the page opened, don't click go button, refresh the page.

I believe it will work with you too.














2006-07-09, 06:19:59
anonymous from Romania  
Hy everybody!


I tried everythink, but still don't work!
I have installed PHP 5.0
MySQL Server 5.0
Apache 2

I still have this: Fatal error: Call to undefined function mysql_connect()
after i make a lot of changes.
If someone could help at Messenger ID: ste_7_e
ThanQ!
2006-11-24, 23:26:15
anonymous from India  
i am getting same error in Fedora Core3 for php ie.., call to undefined function : mysql_connect()
2007-01-27, 09:52:00
[hidden] from South Africa  
rating
I had a similar problem on XP with a CLI invocation of PHP. The reason was that my php.ini file was in a non-standard directory (default WAMP install puts it in the apache bin folder), so if you're giving it a command from the CLI, it looks for the ini file in c:/windows or c:/php, doesn't find it and uses php.ini-dist instead (very restricted). If you don't have a php.ini in the root php folder, copy the ini file from the apache defined location and put it in the root php folder. Voila
2007-02-06, 04:07:37
anonymous from India  
i found error in connecting the mysql to the php .it gives the error,undefined function
mysql_connect().
2007-04-07, 01:39:27
riza441@gmail.com from New Delhi in Delhi, India  


>>>i am getting same error in Fedora Core3 for php ie.., call to undefined function : mysql_connect()
solution:
1 locate the module mysql.so and mysqli.so
2 copy in to thepath which u gave in extension_dir in php.ini
3 make sure un comment the line extension=mysql.so in php.ini

i m sure it will solve ur problem
2007-04-24, 09:02:14
anonymous from India  
Hai

I am getting the error Fatal error: Call to undefined function: mysql_connect();

I tried everything but i didn't resolve it, could any body help me out.

I m using PHP 5, Apache in windows Platform.

Thanx in advance.
2007-04-27, 07:30:06
riza441@gmail.com from India  
rating
1 locate the module mysql.so and mysqli.so
2 copy in to thepath which u gave in extension_dir in php.ini
3 make sure un comment the line extension=mysql.so in php.ini
2007-05-14, 13:30:02
anonymous from Haiti  
i install Apache 2.0.58,php 5.2.1 and mysql 5.0 ,when i try connect with a database that exists on mysql by a sript php, i obtain this error :Fatal error: Call to undefined function mysql_connect() in C:\www\monsite\connect.php on line 2
2007-05-14, 13:36:17
anonymous from Haiti  
i install, configure a web server apache2.0.58,php 5.2.1,mysql5.0,phpmyadmin2.8.1, when i test phpmyadmin i obtain this error : phpMyAdmin - Error
Cannot load mysql extension. Please check your PHP configuration. - Documentation
2007-05-27, 00:11:51
mahiswill@gmail.com from India  
iam also getting same problem please help me
my email. is mahiswill@gmail.com
2007-06-07, 12:00:21
anonymous from Ireland  
rating
This helped me lots ... thanx guys
2007-06-09, 15:36:35
aivjans  
rating
Hello everyone!

I had the same undefined function error!
You all helped me with the solution.

Here's what helped me (I realized this after I had tried many other things using on that infinity of hours).

First get the info about yous PHP with this script:
<?php
echo phpinfo();
?>
Then check 'Configuration File (php.ini) Path'. Check if that is the same as your php.ini file.

This helped in my case. Wish you luck too!
You are on page 1 of 3, other pages: [1] 2 3

 

 

NEW: Optional: Register   Login
Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option, or post under a registered account.
 

Show city and country
Show country only
Hide my location
You can mark text as 'quoted' by putting [quote] .. [/quote] around it.
Please type in the code:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity.
The owner of this web site reserves the right to delete such material.

photo Add a picture: