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 installed.
[root@localhost html]# rpm -qa | grep -i 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

[root@localhost html]# rpm -qa | grep -i 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
perl-DBD-MySQL-4.013-3.el6.i686

Can anyone please help me for this.

Thanks

Add:

extension=mysql.so

to php.ini or check if there is a mysql.ini file in /etc/php5/apache2/conf.d and place this directive there, then reload the server:

sudo service apache2 reload

bye!

I have added extension=mysql.so in php.ini and restarted httpds but it is not changing the error.

Are you sure you have the mysql.so file?

Apart from this problem: the mysql extension is about to be deprecated. I advise you to switch to mysqli or PDO instead.

I could not find mysql.so file. But I have installed all the packages of mysql available in yum.

I have got that now, but nothing is improving.
[root@localhost ~]# find / -name mysql.so
/usr/lib/php/modules/mysql.so

Be aware that there is more then a php.ini file, one for cli, one for apache2. If you have the conf.d directory place the loader there, because this is a directory shared between the two versions. I don't have other ideas, sorry.

I have solved the problem now, I have installed linux freshly, installed php, mysql, php-mysql and it started working good. Thanks for all the suggestions to solve

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.