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 3 of 3, other pages: 1 2 [3]
2008-09-05, 17:50:46
anonymous from Canada  
I had the same problem and none of the solutions from the web helped me.

I fixed it by myself.

It is caused by the fact that the PHP path is set in the Path system variable. However, before restarting Apache with the new system variable, the dll cannot be found. The solutions are: 1. restart the computer 2. shutdown apache, open a new command window and run httpd.exe (Please notice that restarting Apache server using Apache Monitor does not work, because Apache Monitor is still using the same Path environment variable)
2008-09-18, 02:03:53
anonymous from Malaysia  
rating
Hi Everyone, I Spent over 6 hours trying to figure out how to stop this error and how to connect to the database. I checked about 20 forums trying to apply their steps to make the PHP identify the MYSQL functions... at last nothing Helped so my friend told me 'man just install XAMPP and it will do everything for you' , I Installed it .. it needs 0 configuration .. Really you dont have to do anything except creating ur database so If you are confused just go to this website > http://www.apachefr..s.html<

I am sure that it will work 100%
2008-11-18, 16:34:02
anonymous from Argentina  
rating
Hello,
after fighting and fighting I found that the problem was that I had my PHP App installed under Program Files !!

I uninstalled, and reinstalled under C:\ and there you go.. no more errors !!

Thanks all !!
2008-11-20, 11:19:02
anonymous from United States  
Thanks riza - that did the trick for me!
2008-11-23, 22:00:10
[hidden] from Serbia  
rating
I solved my problem by copy libmySQL.dll to windows\system32 directoty after setting up correct extension directive and uncomenting adequat extensions in proper php.ini file.
2009-01-25, 08:43:30
anonymous from Pakistan  
just tell me what to do with what file to run mysql with PHP and Apache if you are sure. Because I am doing the things but can't connect to mysql.
Where/what to set its port or other things in what file.
I shall be thankful.
2009-02-06, 22:31:06
anonymous from Canada  
Step #6 of the list below SOLVED it for me. If you have Apache installed to c:\www\, and php installed to c:\www\php\ then:

1. Copy php.ini-dist to php.ini
2. Edit php.ini
3. Check line: doc_root = 'c:\www\htdocs'
4. Check line: extension=php_mysql.dll
5. Check line: extension_dir = './ext'
6. Copy libmysql.dll to C:\WINDOWS


1. Control Panel > System > Advanced > Environment Variables
2. Edit 'PATH' variable, and append ';C:\www\php' or set 'C:\www\php' alone.
3. Click Okay.
2009-08-03, 12:52:51
anonymous from India  
rating
Hi all,

This thread helped me a lot.
Really nice.

Thanks a lot.

Regards,
Ankzz
2010-02-21, 22:28:10
anonymous from Taiwan  
If you still have a problem to call for mysql_connect() after you have tried everything else, you might want to run your php script from command line to find out if there is anyting wrong in your php.ini.

If you use a unix like OS you should do:
/yourpath/php -f /yourpath/script.php

For windows OS's do:
c:\yourpath\php.exe -f c:\yourpath\script.php


2010-03-01, 09:32:38
anonymous from United Kingdom  
Isn't that code just to get PHP running as a module automatically. I'm having the same problems as many other people here is what I have tried.

Copied dll file from mysql to php.
enabled database support in php.ini file for my database software.
checked details in the conf file for my database conection details.

BUT I still get same sql error connection to undefined function on line 6 ()

for the guy finding the dll file its in the database software
navigate to your software through the start menu. It will open a library of dll files.

Thanks for any help.
2010-03-02, 13:28:17   (updated: 2010-03-02, 13:31:14)
anonymous from United Kingdom  
I am going to assume that you have apache already installed in a directory C:\Program Files\Apache Software Foundation\Apache2.2.

Download and install PHP from http://www.php.net/..loads.php, you should grab the newest 5.x.x Windows Binaries zip package that will work on apache.

(Do NOT use the 'PHP Installer' version.)

create a folder named php in you C directory so you have structure C:\php\

then unzip php files to this folder.

locate the file 'php.ini-dist' create a copy and rename it to php.ini

Open php.ini in a text editor and scroll down about halfway through the file and look for doc_root then change it to point to whatever your Apache DocumentRoot is set to. (i.e. the name you set the document root to in the apache configuration file)
In my case C:/Apache Sites.

Scroll down about 7 more lines and change the extension_dir from extension_dir = './' to the location of the 'ext' directory after you unzipped PHP. in my case: extension_dir = 'C:\php\ext'

scroll down to find the line

;extension=php_mysql.dll

remove the semicolon at the front so it reads

extension=php_mysql.dll

save and exit php.ini

Using Notepad open httpd.conf (should be start-menu shortcut 'Apache HTTP Server 2.2 > Configure Apache Server > Edit the Apache httpd.conf Configuration File').

Either at the very beginning or end of the file add the following lines:

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

save and exit your apache config file (httpd.conf)

Now to get your mysql up and running you need to copy some dynamic link library (dll) files from your php folder to your apache folder.

Go to your php folder on your c drive C:\php\ and copy the following files:

fdftk.dll
gds32.dll
libeay32.dll
libmhash.dll
libmysql.dll
msql.dll
ntwdblib.dll
php5apache2_2.dll
php5apache.dll
php5apache_hooks.dll
php5isapi.dll
php5nsapi.dll
php5ts.dll
php_mysql.dll
php_mssql.dll
php_mysql.dll
php_mysqli.dll
ssleay.dll

some of these files are located in the C:\php\ext folder

Make sure you copy these files to your apache folder, in my case 'C:\Program Files\Apache Software Foundation\Apache2.2'

Then restart Apache.

If you haven't already done so create a test.php file in your Apache 'DocumentRoot' folder (C:\Apache Sites in my case). In your test.php file, type these 3 lines and then load the file in your browser like http://localhost/test.php (you should get a whole long list of php variables, settings, etc):

<?php
phpinfo();
?>

If you navigate to this page in a browser http://localhost/test.php
You should now find that you have a mysql section and your mysql is up and running!

Hope this helps

Mike Dee
2010-05-10, 04:05:01
anonymous from India  
Thanks you saved my time too.!: )
2010-06-01, 18:59:51
sushil from United States  
Hello everyone,
Even I was facing with same problem. I read many forums and tried everything, but of no use. Atlast i have renamed 'php.ini' file in the root php directory(the folder in which you installed your php) to just 'php' and it worked for me.

STEPS to modify php:

# I unzipped PHP to:
C:\php\

# Rename php.ini-dist (In my case C:\php\php.ini-dist) to php (just php...dont rename to php.ini)

#Edit your php.ini
Open php.ini in a text editor and scroll down about halfway through the file and look for doc_root then change it to point to whatever your Apache DocumentRoot is set to.
In my case:
doc_root = 'C:\Apache\htdocs'


Scroll down about 7 more lines and change the extension_dir from extension_dir = './' to the location of the ext directory after you unzipped PHP.
In my case:
extension_dir = 'C:\php\ext'


search for
;extension=php_mysql.dll
and remove the
;
infont of that line

#Copy libmysql.dll file from your php folder to 'C:\Windows\System32'

#Editing Apache Conf File
In my case 'C:\Apache\conf\httpd' with notepad.
At the end of the file add the below code without any quotations and all.
LoadModule php5_module 'C:/php/php5apache2_2.dll'
    AddType application/x-httpd-php .php
    PHPIniDir 'C:/php'


#Testing:
Restart Apache.
create a test.php file in your Apache 'DocumentRoot' folder ('C:\Apache\htdocs' in my case). In your test.php file, type these 3 lines and then load the file in your Internet browser like http://localhost/test.php (you should get a whole long list of php variables, settings, etc):

<?php
phpinfo();
?>



my_connect command should also work when you install and configure mysql properly.

* This should work for you. Incase it doesnt work
Download connectors for php from mysql website.
http://dev.mysql.co..nnector/c/

Unzip it. You would be getting libmysql.dll file . Copy this file to C:\Windows\System32.
It takes lot of Trial and error. All the best.

my email : sushtaurus@gmail.com


Keywords:
2012-06-11, 07:43:38
jaffa from India  
rating
In the earliest database systems, efficiency was perhaps the primary concern, but it was already recognized that there were other important objectives. One of the key aims was to make the data independent of the logic of application programs, so that the same data could be made available to different applications. Thanks.
Regards,
http://www.fivebuttons.com/
2012-10-11, 00:11:50
anonymous  
sdwessda
You are on page 3 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: