致命错误:调用C:\Apache\htdocs\测试中的未定义函数mysql_connect()。php在第2行

时间:2022-09-23 23:56:06

Fatal error: Call to undefined function mysql_connect() in C:\Apache\htdocs\test.php on line 2

致命错误:调用C:\Apache\htdocs\测试中的未定义函数mysql_connect()。php在第2行

I've spent 11 hours today trying to get past this ONE problem.

我今天花了11个小时来解决这个问题。

I have installed: MySQL 5.1 Apache 2.2.14 PHP 5.2.17

我安装了:MySQL 5.1 Apache 2.2.14 PHP 5.2.17

these were the versions referred to in the book "PHP and MySQL".

这些是《PHP和MySQL》一书中提到的版本。

When I run the script:

当我运行脚本时:

<?php
mysql_connect ('localhost', 'root', 'password');
?>

where localhost, root and password are the REAL values for this given test system and all I have seen is:

其中localhost、root和password是这个给定测试系统的真实值,我所看到的是:

Fatal error: Call to undefined function mysql_connect() in C:\Apache\htdocs\test.php on line 2

致命错误:调用C:\Apache\htdocs\测试中的未定义函数mysql_connect()。php在第2行

4 个解决方案

#1


18  

Uncomment the line extension=php_mysql.dll in your "php.ini" file and restart Apache.

取消= php_mysql线延伸。在你的“php dll。文件和重新启动Apache。

Additionally, "libmysql.dll" file must be available to Apache, i.e., it must be either in available in Windows systems PATH or in Apache working directory.

此外,“libmysql。“dll”文件必须对Apache可用,即。它必须在Windows系统路径或Apache工作目录中可用。

See more about installing MySQL extension in manual.

有关在手册中安装MySQL扩展的更多信息,请参阅。

P.S. I would advise to consider MySQL extension as deprecated and to use MySQLi or even PDO for working with databases (I prefer PDO).

另外,我建议不使用MySQL扩展,使用MySQLi甚至PDO来处理数据库(我更喜欢PDO)。

#2


3  

I had the similar issue. I solved it the following way after a number of attempts to follow the pieces of advice in the forums. I am reposting the solution because it could be helpful for others.

我也有类似的问题。在尝试了很多次之后,我用下面的方法解决了这个问题。我将重新发布解决方案,因为它可能对其他人有帮助。

I am running Windows 7 (Apache 2.2 & PHP 5.2.17 & MySQL 5.0.51a), the syntax in the file "httpd.conf" (C:\Program Files (x86)\Apache Software Foundation\Apache2.2\conf\httpd.conf) was sensitive to slashes. You can check if "php.ini" is read from the right directory. Just type in your browser "localhost/index.php". The code of index.php is the following:

我正在运行Windows 7 (Apache 2.2 & PHP 5.2.17和MySQL 5.0.51a),文件“httpd”中的语法。(C:\Program Files (x86)\Apache Software Foundation\Apache2.2\conf\httpd.conf)对斜线很敏感。您可以检查“php”。ini是从正确的目录中读取的。只需在浏览器中输入“localhost/index.php”。索引的代码。php是以下几点:

<?php echo phpinfo(); ?>

< ?php echo phpinfo();? >

There is the row (not far from the top) called "Loaded Configuration File". So, if there is nothing added, then the problem could be that your "php.ini" is not read, even you uncommented (extension=php_mysql.dll and extension=php_mysqli.dll). So, in order to make it work I did the following step. I needed to change from

有一行(离顶部不远)称为“已加载配置文件”。因此,如果没有添加任何东西,那么问题可能就是您的“php”。“ini”未被读取,甚至未被注释(extension=php_mysql)。dll和扩展= php_mysqli.dll)。为了让它工作,我做了下面的步骤。我需要改变。

PHPIniDir 'c:\PHP\'

PHPIniDir“c:\ PHP \”

to

PHPIniDir 'c:\PHP'

PHPIniDir“c:\ PHP”

Pay the attention that the last slash disturbed everything!

注意,最后一个斜杠打乱了一切!

Now the row "Loaded Configuration File" gets "C:\PHP\php.ini" after refreshing "localhost/index.php" (before I restarted Apache2.2) as well as mysql block is there. MySQL and PHP are working together!

现在行“已加载配置文件”获取C:\PHP\ PHP。ini”后刷新“localhost /索引。php“(在我重启Apache2.2之前)和mysql块都在那里。MySQL和PHP一起工作!

#3


0  

Change the database.php file from

修改数据库。php文件从

$db['default']['dbdriver'] = 'mysql';

to

$db['default']['dbdriver'] = 'mysqli';

#4


-5  

i had the same problem and used this code below and it worked:

我也遇到了同样的问题,使用了下面的代码。

<?php
$link = mysqli_connect("localhost","root","") or die ("Couldn't not connect");
mysqli_select_db($link, "Enter your project name here");
?>

#1


18  

Uncomment the line extension=php_mysql.dll in your "php.ini" file and restart Apache.

取消= php_mysql线延伸。在你的“php dll。文件和重新启动Apache。

Additionally, "libmysql.dll" file must be available to Apache, i.e., it must be either in available in Windows systems PATH or in Apache working directory.

此外,“libmysql。“dll”文件必须对Apache可用,即。它必须在Windows系统路径或Apache工作目录中可用。

See more about installing MySQL extension in manual.

有关在手册中安装MySQL扩展的更多信息,请参阅。

P.S. I would advise to consider MySQL extension as deprecated and to use MySQLi or even PDO for working with databases (I prefer PDO).

另外,我建议不使用MySQL扩展,使用MySQLi甚至PDO来处理数据库(我更喜欢PDO)。

#2


3  

I had the similar issue. I solved it the following way after a number of attempts to follow the pieces of advice in the forums. I am reposting the solution because it could be helpful for others.

我也有类似的问题。在尝试了很多次之后,我用下面的方法解决了这个问题。我将重新发布解决方案,因为它可能对其他人有帮助。

I am running Windows 7 (Apache 2.2 & PHP 5.2.17 & MySQL 5.0.51a), the syntax in the file "httpd.conf" (C:\Program Files (x86)\Apache Software Foundation\Apache2.2\conf\httpd.conf) was sensitive to slashes. You can check if "php.ini" is read from the right directory. Just type in your browser "localhost/index.php". The code of index.php is the following:

我正在运行Windows 7 (Apache 2.2 & PHP 5.2.17和MySQL 5.0.51a),文件“httpd”中的语法。(C:\Program Files (x86)\Apache Software Foundation\Apache2.2\conf\httpd.conf)对斜线很敏感。您可以检查“php”。ini是从正确的目录中读取的。只需在浏览器中输入“localhost/index.php”。索引的代码。php是以下几点:

<?php echo phpinfo(); ?>

< ?php echo phpinfo();? >

There is the row (not far from the top) called "Loaded Configuration File". So, if there is nothing added, then the problem could be that your "php.ini" is not read, even you uncommented (extension=php_mysql.dll and extension=php_mysqli.dll). So, in order to make it work I did the following step. I needed to change from

有一行(离顶部不远)称为“已加载配置文件”。因此,如果没有添加任何东西,那么问题可能就是您的“php”。“ini”未被读取,甚至未被注释(extension=php_mysql)。dll和扩展= php_mysqli.dll)。为了让它工作,我做了下面的步骤。我需要改变。

PHPIniDir 'c:\PHP\'

PHPIniDir“c:\ PHP \”

to

PHPIniDir 'c:\PHP'

PHPIniDir“c:\ PHP”

Pay the attention that the last slash disturbed everything!

注意,最后一个斜杠打乱了一切!

Now the row "Loaded Configuration File" gets "C:\PHP\php.ini" after refreshing "localhost/index.php" (before I restarted Apache2.2) as well as mysql block is there. MySQL and PHP are working together!

现在行“已加载配置文件”获取C:\PHP\ PHP。ini”后刷新“localhost /索引。php“(在我重启Apache2.2之前)和mysql块都在那里。MySQL和PHP一起工作!

#3


0  

Change the database.php file from

修改数据库。php文件从

$db['default']['dbdriver'] = 'mysql';

to

$db['default']['dbdriver'] = 'mysqli';

#4


-5  

i had the same problem and used this code below and it worked:

我也遇到了同样的问题,使用了下面的代码。

<?php
$link = mysqli_connect("localhost","root","") or die ("Couldn't not connect");
mysqli_select_db($link, "Enter your project name here");
?>