简体   繁体   English

致命错误:调用未定义的函数mysql_connect()

[英]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: 我收到此错误致命错误:在第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();
?>

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.ini file: 我也编辑了/etc/php.ini文件:

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: 你应该打开位于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

if you are working on linux [debian] 如果你正在使用linux [debian]

apt-get install php5-mysql apt-get install php5-mysql

because your PHP is not able to talk with mysql 因为你的PHP无法与mysql交谈

I cheated and looked on my phone 我骗了,看了看我的手机

The build of your PHP spectifically says '--without-mysql' 你的PHP的构建有点说'--with-mysql'

Therefore, mysql functions will not be available. 因此,mysql函数将不可用。

You should rebuild. 你应该重建。

Your PHP is configured with --without-mysql . 您的PHP配置了--without-mysql

The documentation describes how to configure with mysql extension enabled. 文档描述了如何配置启用mysql扩展。 You may have your reasons, but PDO would be a better choice here is the documentation for configuring with PDO mysql. 您可能有自己的理由,但PDO是更好的选择,这里是配置PDO mysql的文档

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM