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 2 of 3, other pages: 1 [2] 3
2007-06-25, 02:41:01
anonymous from India  
Hi,

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. using this forum.

please anybody help my e-mail: kanesh_san@yahoo.com

thank u,
ganesh
2007-08-14, 16:04:23
anonymous from Norway  
rating
For Windows users, reboot computer after installing php, as it makes some changes to your systems variables that isn't automatically loaded after install. (linux ftw!)
2007-10-24, 01:03:20
madanji_choudhary@yahoo.com from New Delhi, India  
rating
Hi, I am using php5.2.4, mysql 5.0.27 and apache 2.2.6 on windowsXP. While trying to connect with mysql, i get a message 'Falat Error: unable to call undefined function mysql_connect()'

Please help me. I will be thankful for your help

Madan
Email Id: madanji.choudhary@yahoo.com
2007-12-11, 17:31:33
milos.milovanovic,at,gmail,com from Spain  
After the whole day and after applying all advices I found on the net, finally when I copied libmysql.dll from MySQL Server 5.0\bin directory to the C:\PHP\ext directory I got the solution :)
2008-02-11, 06:35:37
Thato,Mantai from South Africa  
Copy \PHP\libmysql.dll to the \windows\system32 if you were running mysql on windows
2008-03-02, 07:01:11
anonymous from Philippines  
Just follow the instructions below and you'll be fine.... if you just follow....



Install PHP5

1.In Windows Explorer, go to c:\downloads\php5 and unzip the file php-5.0.2-Win32.zip into the directory called C:\download\php5\php-5.0.2-Win32.( in short unzip it to somewhere)
2.You now want to MOVE all the unzipped PHP5 files and directories to c:\php. So in Windows Explorer, go to C:\download\php5\php-5.0.2-Win32\ and press CTRL-A to select all the files, then press CTRL-X to copy them. Now create a directory called c:\php and copy all the files into that directory by going to it and pressing CTRL-V. If you have completed this step correctly, you will see in the c:\php directory four folders and over 20 files.
3.Now move (don't just copy) the file c:\php\php5ts.dll to c:\windows\php5ts.dll (or if you don't have a c:\windows directory, move it to c:\winnt).
4.PHP5 is now installed on your computer, but you still need to configure it to work with Apache, which we will do in the next step.




Configure PHP5 to Work with Apache

1.With the Windows Explorer, create the folder c:\webs\test. This will be our test website.
2.Rename the c:\php\php.ini-dist to c:\php\php.ini, then make the following changes in the c:\php\php.ini file: (1) doc_root = 'c:\webs\test' and (2) extension_dir = 'C:\php\ext'. Note that you should use BACKSLASHES in the php.ini file.
3.In the file C:\Program Files\Apache Group\Apache2\conf\httpd.conf, change the DocumentRoot entry to: DocumentRoot 'C:/webs/test'. Note that you should use FORWARD SLASHES in the http.conf file.
4.Also in the file C:\Program Files\Apache Group\Apache2\conf\httpd.conf, change the Directory entry to: <Directory 'C:/webs/test'>.Note that you should use FORWARD SLASHES in the http.conf file.
5.Again in the C:\Program Files\Apache Group\Apache2\conf\httpd.conf file, add the following lines: hint: to find this position fast, search for 'media types'
    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz
    ScriptAlias /php/ 'c:/php/'
    AddType application/x-httpd-php .php .php5
    Action application/x-httpd-php '/php/php-cgi.exe'
    SetEnv PHPRC 'c:/php'
6.Lastly, we need to make one last change to this C:\Program Files\Apache Group\Apache2\conf\httpd.conf file. Find the 'DirectoryIndex' entry and add 'index.php' to the end of the line as shown in this screenshot.
    *you can copy this text: DirectoryIndex index.html index.html.var index.php5
7.In order for the changes to take effect, you need to restart Apache. To do this, click the Apache symbol in the lower right-hand corner of your task bar. In the little menu that pops up there, click Apache 2 and then Restart.


Test PHP5

1.Create the file c:\webs\test\index.php5 with the following line:Today is <? print strftime('%m/%d/%Y'); ?>
2.With your browser, go to http://localhost. If you see the current date on your screen as in this screenshot, then PHP5 has been successfully installed and configured with Apache.


Set up PHP to work with MySQL 4.1

1.First of all, check the c:\php directory and make sure that the files libmysqli.dll and php_mysqli.dll are both there. If they are not there, check the c:\php\ext directory and copy the files into c:\php
2.Then open up the file c:\php\php.ini in your editor and ADD the line extension=php_mysqli.dll.
3.In order for the changes to take effect, you need to restart Apache. To do this, click the Apache symbol in the lower right-hand corner of your task bar. In the little menu that pops up there, click Apache 2 and then Restart.
4.After about 10 seconds, your PHP will be ready to accept mysqli commands to talk to the MySQL 4.1 database.


Test PHP5/MySQL in browser

1.Create a file c:\webs\test\testmysql41.php and paste in the following code:
    <?

    $mysqli = new mysqli('localhost','root','admin');
    $mysqli->select_db('demo');

    $result = $mysqli->query('SELECT * FROM members');

    while($row = $result->fetch_assoc()) {
    print $row['firstName'] . ' ' . $row['lastName'] . '<br/>';    
    }
2.In your browser, go to http://localhost/te..ql41.php.
3.if you see something that contains ur database, then it worked.
4.If you get the message 'Fatal error: Class 'mysqli' not found in C:\webs\test\nameofphp.php on line 3' or something similar then open ur 'php.ini' file and look for ';extension=php_mysqli.dll' then please REMOVE the ';' in that line.
2008-03-27, 00:51:21
anonymous from India  
Hi,
I am also facing problem but this is solved by suggestion given by
[hidden] from South Africa..Above mention person.
Heartly thanks to this hidden person.
If any one gets such error put ur php.ini fiile in root folder of php.
2008-04-20, 14:15:16
zohaib66@gmail.com  
rating
I've check everything that is written in the whole thread but still recieving the same error

Fatal error: Call to undefined function mysql_connect() in C:\Program Files\Apache Software Foundation\Apache2.2\test\createmovie.php on line 4

I m running it on Windows XP, Please some body share the solution

:'( so many hours are wasted now
2008-04-20, 14:25:02
zohaib66@gmail.com  
rating
Man I just posted my problem and tried once again myself and solved the problem :d

Refering to aivjans post:

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.

Check Configuration File (php.ini) Path and enable php_mysql.dll in php.ini
Copy the libmySQL.dll to windows/system32 folder
RESTART webserver

Hope this solves your problem as it did mine :)
2008-05-09, 05:48:54   (updated: 2008-05-09, 05:51:07)
anonymous from India  
Hi, I am using php5.2.5, mysql 5.0.27 and apache 2.0 on windows2000. While trying to connect with mysql, i get a message Fatal error: Class 'mysqli' not found in C:\Program Files\Apache Group\Apache2\htdocs\mysql.php on line 3
I've check everything that is written in the whole thread but still recieving the same error


Please help me. I will be thankful for your help
2008-05-30, 23:48:01   (updated: 2008-05-30, 23:55:10)
anonymous from India  
hi
this is narsing.
i installed php 5.
when i tried to connect to mysql with php 5

<?php

$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = 'password';

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die('Error connecting to mysql');

?>
it is throwing error like Call to undefined function mysql_connect() in /root/connect_sql.php on line 7
iam using suse 9.3,i configured php.ini like this
i added extension=mysql.so to it
after adding it it is throwing another error like Unable to load dynamic library './msql.so' - ./msql.so: cannot open shared object file: No such file or directory in Unknown on line 0
when i tried to find mysqlso library iam not able to find it .
please somebody help me .
2008-07-17, 23:56:01
anonymous  
thanks buddy it works....
2008-07-29, 21:48:25
anonymous from United States  
just for your atention, for windows , in apache's configuration file: PHPIniDir 'c:\php' .
using backslash in the directory solve the problem in my case. (I used forward slash when I installed apached using instruction).
2008-08-23, 20:19:27
anonymous from United Kingdom  

want to do a forum with php and mysql just
testing 1 2 3....
2008-08-23, 20:22:00
Goldsmiths,student from United Kingdom  


Mysql connection problem with php solved

problem: could not connect

http://www.delphifa..898.shtml
In the Next step I opened a config. file 'httpd.conf' for apache in the apache folder of your program files (i have ver.2.0.52) and added

this content into the bottom of the page.

LoadModule php5_module 'c:/php/php5apache2_2.dll' ( i had this line already so if you remove it you will see php server will not work, so just leave it )

LoadModule php5_module 'c:/php/php5apache2.dll' ( this is the new line which solved the problem )
AddType application/x-httpd-php .php
PHPIniDir 'C:/php'

good luck
You are on page 2 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: