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.
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
if you are working on linux [debian]
because your PHP is not able to talk with mysql
I cheated and looked on my phone
The build of your PHP spectifically says '--without-mysql'
Therefore, mysql functions will not be available.
You should rebuild.
Your PHP is configured with --without-mysql
.
The documentation describes how to configure with mysql extension enabled. You may have your reasons, but PDO would be a better choice here is the documentation for configuring with PDO mysql.
我的解决方案在这里(代码可能对引号和斜杠敏感): 致命错误:调用未定义的函数mysql_connect()无法解决
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.