0

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

3
Contributors
7
Replies
10
Views
5 Years
Discussion Span
Last Post by nit8899
1

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!

0

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

1

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.

0

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

0

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

0

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.

Edited by cereal

1

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.