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

时间:2022-01-03 06:59:56

I have searched the internet for troubleshooting with this "Call to undefined function mysql_connect() " error but none of the suggested procedures works...

我在internet上搜索了以下“调用未定义函数mysql_connect()”的故障排除“错误,但所有建议的程序都不起作用……”

When I try to access mysql from php, I get this error. I have PHP Version 5.2.17 and MySQL 5.1.68 (mysql is running outside php, I tried creating tables and databases etc.).

当我尝试从php访问mysql时,我得到了这个错误。我有PHP版本5.2.17和MySQL 5.1.68 (MySQL在PHP之外运行,我尝试创建表和数据库等)。

I uncomment the extensions in php.ini:

我不评论ph .ini的扩展:

extension=php_mysql.dll
extension=php_mysqli.dll

and specified the path to these extensions.

并指定这些扩展的路径。

I also added both PHP and MySQL to my PATH variable. I am using Apache 2.2. and I restarted the server after every change that I made.

我还在路径变量中添加了PHP和MySQL。我正在使用Apache 2.2。在每次修改之后,我重新启动服务器。

This is my code in php for accessing the database (but I suppose that the problem is not in syntax):

这是我用php编写的用于访问数据库的代码(但我认为问题不在于语法):

<?php     
      $dbhost = 'localhost';
      $dbuser = 'root';
      $dbpass = 'pasw';
      $dbname = 'db';

      $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
      mysql_select_db($dbname);
?>

I am out of ideas how to fix this, can u suggest some other troubleshooting tips? I am quite new to his problematics... I would like to use MySQL, cause thats what I will use on the actual server when I´ll have my website up and running. Thanks in advance!

我不知道如何解决这个问题,你能建议一些其他的故障排除方法吗?我对他的问题很陌生……我想使用MySQL,因为这就是我´时将使用实际的服务器上有我的网站启动和运行。提前谢谢!

EDIT: this is from apache log:

编辑:这来自apache日志:

[Mon Mar 25 13:50:42 2013] [error] [client 127.0.0.1] PHP Fatal error:  Call to undefined function mysql_connect() in C:\\Web\\thenemis\\dbconnect.php on line 7, referer: http://localhost/thenemis/admin.php
[Mon Mar 25 13:50:42 2013] [error] [client 127.0.0.1] File does not exist: C:/Web/favicon.ico

EDIT2: this is from php info (I think that the problem may be with some unspecified parametres in php.ini file). I havent read anywhere that I should specify some other features than extensions and path to them but maybe I was wrong... what do you suggest?

这是来自php info(我认为问题可能是php中某些未指定的参数。ini文件)。我没有在任何地方读到,我应该指定一些其他的特性,而不是扩展和路径,但也许我错了……你有什么建议?

mysql

MySQL Support   enabled
Active Persistent Links 0
Active Links    0
Client API version  5.0.51a

Directive   Local Value Master Value
mysql.allow_persistent  On  On
mysql.connect_timeout   60  60
mysql.default_host  no value    no value
mysql.default_password  no value    no value
mysql.default_port  no value    no value
mysql.default_socket    no value    no value
mysql.default_user  no value    no value
mysql.max_links Unlimited   Unlimited
mysql.max_persistent    Unlimited   Unlimited
mysql.trace_mode    Off Off

4 个解决方案

#1


6  

As it was already said use phpinfo() for determining if mysql is running correctly. In general you should not use mysql anymore more but rather the new improved version of mysql, called mysqli http://php.net/manual/de/book.mysqli.php

如前所述,使用phpinfo()来确定mysql是否正常运行。一般来说,不应该再使用mysql,而应该使用新的改进版mysql,即mysqli http://php.net/manual/de/book.mysqli.php

You can in addition programmatically check if a function exists with method_exists method

此外,还可以通过编程检查一个函数是否存在method_exists方法

#2


3  

Try to use this:

尝试使用:

$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = 'pasw';
$dbname = 'db';

<?php
// Create connection
$con=mysqli_connect($dbhost,$dbuser,$dbpass,$dbname);

// Check connection
if (mysqli_connect_errno($con))
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
?>

MySQL support will be removed of PHP, so start to use MySQLi or PDO instead.

PHP将删除MySQL支持,因此开始使用MySQLi或PDO。

:)

:)

#3


2  

Verify that your installation of PHP has been compiled with mysql support. Create a test php file containing <?php phpinfo(); exit(); ?> and run it in your browser. Search the page for keyword 'MySQL'. If you don't see it, you need to recompile PHP with MySQL support, or reinstall a PHP package that has it built-in.

验证您的PHP安装已经使用mysql支持进行编译。创建一个包含 并在浏览器中运行。搜索关键字“MySQL”。如果没有看到,需要使用MySQL支持重新编译PHP,或者重新安装内置PHP包。

Open your terminal and run bellow command.

打开终端,运行bellow命令。

sudo apt-get install mysql-server

If you are running PHP you will also need to install the php module for mysql

如果您正在运行PHP,您还需要为mysql安装PHP模块

sudo apt-get install php5-mysql

#4


0  

I set the path for PHP in the system variable of my computer, edited the path value to C:/program files/php; and enabled extension=php_mysqli.dll in php.ini.

在我的计算机系统变量中设置PHP的路径,将路径值编辑为C:/program files/ PHP;和启用扩展= php_mysqli。dll在php . ini中。

Then I used this function

然后我用了这个函数

mysqli_connect($host,$username,$password)or die(mysql_error()); 

And after that a system restart. It worked for me; I hope it works for you.

然后系统重新启动。它为我工作;我希望它对你有用。

#1


6  

As it was already said use phpinfo() for determining if mysql is running correctly. In general you should not use mysql anymore more but rather the new improved version of mysql, called mysqli http://php.net/manual/de/book.mysqli.php

如前所述,使用phpinfo()来确定mysql是否正常运行。一般来说,不应该再使用mysql,而应该使用新的改进版mysql,即mysqli http://php.net/manual/de/book.mysqli.php

You can in addition programmatically check if a function exists with method_exists method

此外,还可以通过编程检查一个函数是否存在method_exists方法

#2


3  

Try to use this:

尝试使用:

$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = 'pasw';
$dbname = 'db';

<?php
// Create connection
$con=mysqli_connect($dbhost,$dbuser,$dbpass,$dbname);

// Check connection
if (mysqli_connect_errno($con))
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
?>

MySQL support will be removed of PHP, so start to use MySQLi or PDO instead.

PHP将删除MySQL支持,因此开始使用MySQLi或PDO。

:)

:)

#3


2  

Verify that your installation of PHP has been compiled with mysql support. Create a test php file containing <?php phpinfo(); exit(); ?> and run it in your browser. Search the page for keyword 'MySQL'. If you don't see it, you need to recompile PHP with MySQL support, or reinstall a PHP package that has it built-in.

验证您的PHP安装已经使用mysql支持进行编译。创建一个包含 并在浏览器中运行。搜索关键字“MySQL”。如果没有看到,需要使用MySQL支持重新编译PHP,或者重新安装内置PHP包。

Open your terminal and run bellow command.

打开终端,运行bellow命令。

sudo apt-get install mysql-server

If you are running PHP you will also need to install the php module for mysql

如果您正在运行PHP,您还需要为mysql安装PHP模块

sudo apt-get install php5-mysql

#4


0  

I set the path for PHP in the system variable of my computer, edited the path value to C:/program files/php; and enabled extension=php_mysqli.dll in php.ini.

在我的计算机系统变量中设置PHP的路径,将路径值编辑为C:/program files/ PHP;和启用扩展= php_mysqli。dll在php . ini中。

Then I used this function

然后我用了这个函数

mysqli_connect($host,$username,$password)or die(mysql_error()); 

And after that a system restart. It worked for me; I hope it works for you.

然后系统重新启动。它为我工作;我希望它对你有用。