php 致命错误:调用未定义的函数 mysql_connect()
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12783589/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Fatal error: Call to undefined function mysql_connect()
提问by nitxx
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:
我收到此错误致命错误: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:
我的系统中安装了 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
output of phpinfo() : http://jsfiddle.net/nit8899/GZ4f7/
phpinfo() 的输出:http: //jsfiddle.net/nit8899/GZ4f7/
Also I have edited the /etc/php.inifile:
我也编辑了/etc/php.ini文件:
extension=mysql.so
But even then I am getting this error.
但即便如此,我还是收到了这个错误。
回答by otporan
You should open your php.ini file located in php folder, and uncomment this line of code:
您应该打开位于 php 文件夹中的 php.ini 文件,并取消注释这行代码:
;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
您的 php 文件夹位置取决于您的 lampp/wampp 安装,如果使用 xampp,它位于:xampp/php/php.ini
回答by Divyesh Singhal
if you are working on linux [debian]
如果你正在使用 linux [debian]
apt-get install php5-mysql
apt-get 安装 php5-mysql
because your PHP is not able to talk with mysql
因为您的 PHP 无法与 mysql 对话
回答by BugFinder
I cheated and looked on my phone
我被骗了,看着我的手机
The build of your PHP spectifically says '--without-mysql'
您的 PHP 的构建特别指出“--without-mysql”
Therefore, mysql functions will not be available.
因此,mysql 函数将不可用。
You should rebuild.
你应该重建。
回答by piddl0r
Your PHP is configured with --without-mysql.
您的 PHP 配置为--without-mysql.
The documentationdescribes how to configure with mysql extension enabled. You may have your reasons, but PDO would be a better choice here is the documentationfor configuring with PDO mysql.
该文档描述了如何在启用 mysql 扩展的情况下进行配置。您可能有自己的原因,但 PDO 是更好的选择,这里是使用 PDO mysql 进行配置的文档。
回答by Darius Miliauskas
My solution is here (the code could be sensitive to quotation marks and slashes): Fatal error: Call to undefined function mysql_connect() cannot solve
我的解决方案在这里(代码可能对引号和斜杠敏感):致命错误:调用未定义的函数 mysql_connect() 无法解决

