Php – Fatal error: Call to undefined function thesql_connect()

PHP

I am getting this error Fatal error: Call to undefined function mysql_connect() in /var/www/html/test1.php on line 8
for the following code:

<?php
$host = "localhost";
$user = "user12";
$pass = "34klq*";
ini_set ('display_errors', 1);
$r = mysql_connect($host, $user, $pass);
if (!$r) {
echo "Could not connect to server\n";
trigger_error(mysql_error(), E_USER_ERROR);
} else {
echo "Connection established\n";
}
echo mysql_get_server_info() . "\n";
mysql_close();
?>

I have PHP, MYSQL, php-Mysql installed in my system:

[root@localhost ~]# rpm -qa | grep mysql
php-mysql-5.3.3-3.el6_2.8.i686
mysql-devel-5.1.61-4.el6.i686
mysql-server-5.1.61-4.el6.i686
mysql-bench-5.1.61-4.el6.i686
mysql-libs-5.1.61-4.el6.i686
mysql-5.1.61-4.el6.i686

[root@localhost ~]# rpm -qa | grep php 
php-common-5.3.3-3.el6_2.8.i686
php-5.3.3-3.el6_2.8.i686
php-mysql-5.3.3-3.el6_2.8.i686
php-cli-5.3.3-3.el6_2.8.i686
php-pdo-5.3.3-3.el6_2.8.i686

output of phpinfo() :
http://jsfiddle.net/nit8899/GZ4f7/

Also I have edited the /etc/php.ini file:

extension=mysql.so

But even then I am getting this error.

Best Answer

You should open your php.ini file located in php folder, and uncomment this line of code:

;extension=php_mysql.dll

So it looks like this:

extension=php_mysql.dll

Your php folder location depends on your lampp/wampp installation, if using xampp its located in: xampp/php/php.ini