We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,106 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Fatal error: Call to undefined function mysql_connect()

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
21 Hours
Discussion Span
7 Months Ago
Last Updated
8
Views
Question
Answered
nit8899
Newbie Poster
5 posts since Oct 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

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!

cereal
Veteran Poster
1,145 posts since Aug 2007
Reputation Points: 344
Solved Threads: 222
Skill Endorsements: 22

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

nit8899
Newbie Poster
5 posts since Oct 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

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.

pritaeas
Posting Prodigy
Moderator
9,287 posts since Jul 2006
Reputation Points: 1,173
Solved Threads: 1,459
Skill Endorsements: 86

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

nit8899
Newbie Poster
5 posts since Oct 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

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

nit8899
Newbie Poster
5 posts since Oct 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 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.

cereal
Veteran Poster
1,145 posts since Aug 2007
Reputation Points: 344
Solved Threads: 222
Skill Endorsements: 22

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

nit8899
Newbie Poster
5 posts since Oct 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0
Question Answered as of 7 Months Ago by cereal and pritaeas

This question has already been solved: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0828 seconds using 2.74MB