Monday, June 15, 2009

Call to undefined function: mysql_connect(). Please install the MySQL Connector for PHP

Error Description
In RedHat Linux, you have installed the PHP, MySQL, and Apache packages through the package manager. After starting the MySQL and Apache services through the service manager, whenever you try to view any web page that needs access the MySQL database it fails with error message,
Call to undefined function: mysql_connect(). Please install the MySQL Connector for PHP

Cause of the Problem
The mysql.so extension library does not come with the PHP or MySQL distributions. It must be installed separately by downloading any rpm package of php-mysql RPM.

Solution of the Problem
Step 01: Verify that PHP installation has been compiled with mysql support.
Write the following code and save it into a file and the load it into browser.

<?php
phpinfo();
?>

If PHP installation has been compiled with mysql support then in the browser you will see the output like,

mysql

MySQL Supportenabled
Active Persistent Links 0
Active Links 0
Client API version 5.0.51a

DirectiveLocal ValueMaster Value
mysql.allow_persistentOnOn
mysql.connect_timeout6060
mysql.default_hostno valueno value
mysql.default_passwordno valueno value
mysql.default_portno valueno value
mysql.default_socketno valueno value
mysql.default_userno valueno value
mysql.max_linksUnlimitedUnlimited
mysql.max_persistentUnlimitedUnlimited
mysql.trace_modeOffOff



If you don't see above then, you need to recompile PHP with MySQL support, or reinstall a PHP package that has it built-in.

Step 02: Check for settings inside php.ini file.
Check for php.ini file.
Be sure in linux the line
extension=mysql.so
is uncommented.

If you are on windows machine then check the line
extension=php_mysql.dll
is uncommented.

You can uncomment by simply removing preceding semi-colon of the line.
Also make sure that extension_dir is set to correctly to PHP extensions location.
Like,
extension_dir = "C:\php\ext"
This line tells PHP that all PHP extensions are located to C:\php\ext.

Step 03: Check for php-mysql package.
Check if the php-mysql package is installed on the system. To do it,
open a terminal window, and issue,
#rpm -qa | grep php

If you don't see php-mysql package then your php-mysql package is not installed.

Step 04: Install php-mysql package.
Find the php-mysql RPM for the version of PHP that is installed on your system. From google you can search for rpm packages of php-mysql and then you can download and install. Install the rpm package by,
rpm -i php-mysql-release_name.rpm

Alternative if you have yum configured then,
#yum search php //this will show all the available packages you can install.
#yum install php-mysql.i386 // this will install the mysql connector.

Step 05: Install any dependency if exists.
You might also need MySQL-shared-compat RPM if you get a dependency of libmysqlclient.so.10 error while installing.

Step 06: Restart Apache.
You are almost done. The last step is need to restart your apache server.
You can do this by two ways.
a)If you have correct path settings then,
#apachectl restart

or
b)
#/etc/rc.d/init.d/httpd restart

Related Documents

No comments:

Post a Comment