2

我收到此错误致命错误:在第 8 行的 /var/www/html/test1.php 中调用未定义函数 mysql_connect() 以获取以下代码:

<?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();
?>

我的系统中安装了 PHP、MYSQL、php-Mysql:

[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

phpinfo() 的输出:http: //jsfiddle.net/nit8899/GZ4f7/

我还编辑了/etc/php.ini文件:

extension=mysql.so

但即便如此,我也收到了这个错误。

4

5 回答 5

2

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

于 2012-10-08T14:21:26.300 回答
1

如果您正在使用 linux [debian]

apt-get 安装 php5-mysql

因为您的 PHP 无法与 mysql 通信

于 2014-11-24T11:21:26.747 回答
0

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.

于 2012-10-08T14:21:07.673 回答
0

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.

于 2012-10-08T14:21:11.553 回答
0

我的解决方案在这里(代码可能对引号和斜杠敏感):致命错误:调用未定义函数mysql_connect()无法解决

于 2013-09-18T11:51:49.230 回答