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

时间:2022-09-23 23:47:36

I have MySQL (5.5.23 Community Server), Apache (2.2), and PHP (5.3.13) running on a Fedora 15 machine (64-bit). Each works with no problem on their own.

我在Fedora 15计算机(64位)上运行MySQL(5.5.23社区服务器),Apache(2.2)和PHP(5.3.13)。每个工作都没有问题。

I thought that PHP was configured/compiled to work with MySQL, but when I try to load any PHP web page which makes a MySQL call then I get the above noted fatal error (in the Apache error log). PHP works okay on its own though, through Apache and at the command line.

我认为PHP已配置/编译为与MySQL一起使用,但是当我尝试加载任何进行MySQL调用的PHP网页时,我得到了上述致命错误(在Apache错误日志中)。 PHP可以通过Apache和命令行自行运行。

When I run php -i from the command line then sure enough it shows all the MySQL bits and pieces, but when I load a page displaying phpinfo() then there are no MySQL modules mentioned.

当我从命令行运行php -i时,确定它显示了所有MySQL的零碎,但当我加载显示phpinfo()的页面时,则没有提到的MySQL模块。

I've also tried un-commenting "extension=mysql.so" in php.ini, but PHP then complains with "PHP Startup: Unable to load dynamic library '/usr/lib64/php/modules/mysql.so'." (even though the module does reside there). But then I'm not entirely certain whether that line is required to be un-commented or not. [correction: the error stated was actually due to a typo, but running from the command line shows that the module is already loaded anyway - there is a warning from PHP that says so.]

我也尝试在php.ini中取消注释“extension = mysql.so”,但PHP然后抱怨“PHP启动:无法加载动态库'/usr/lib64/php/modules/mysql.so'。” (即使模块确实驻留在那里)。但是,我不完全确定该行是否需要不被评论。 [更正:声明的错误实际上是由于拼写错误,但是从命令行运行表明该模块已经加载了 - 但是有一条来自PHP的警告说明了这一点。]

I've also disabled SELinux; stopped/restarted Apache numerous times; yummed MySQL-Devel, in case it made any difference; and, it seems, every other possible thing.

我也禁用了SELinux;多次停止/重启Apache; yummed MySQL-Devel,以防它有任何区别;似乎还有其他可能的事情。

If I run a little PHP test script from the command line, to access the MySQL database, then it works with no problem, so PHP does know about MySQL, but when it runs under Apache it seems to have no clue that MySQL even exists.

如果我从命令行运行一个小的PHP测试脚本,访问MySQL数据库,那么它没有问题,所以PHP确实知道MySQL,但是当它在Apache下运行时,它似乎不知道MySQL甚至存在。

I've been trying on and off for months to solve this problem, and seem to have tried everything, but nothing seems to work.

几个月来我一直在努力解决这个问题,似乎已经尝试了一切,但似乎没有任何效果。

I don't mind having to re-install PHP if I really have to, if somebody can demonstrate the proper way to configure/compile with MySQL support, so that I can get it to work under Apache, although ideally I'd simply prefer to get the existing installation working.

我不介意重新安装PHP,如果我真的需要,如果有人可以演示配置/编译MySQL支持的正确方法,那么我可以让它在Apache下工作,虽然理想情况下我只是喜欢让现有的安装工作。

Many thanks in advance for any assistance!

非常感谢您的任何帮助!

7 个解决方案

#1


63  

In case anyone else faces this, it's a case of PHP not having access to the mysql client libraries. Having a MySQL server on the system is not the correct fix. Fix for ubuntu (and PHP 5):

如果其他人都面临这种情况,那就是PHP无法访问mysql客户端库的情况。在系统上安装MySQL服务器不是正确的解决方法。修复ubuntu(和PHP 5):

sudo apt-get install php5-mysql

After installing the client, the webserver should be restarted. In case you're using apache, the following should work:

安装客户端后,应重新启动Web服务器。如果您正在使用Apache,以下应该工作:

sudo service apache2 restart

#2


16  

Keep in mind that as of PHP 5.5.0 the mysql_connect() function is deprecated, and it is completely removed in PHP 7

请记住,从PHP 5.5.0开始,不推荐使用mysql_connect()函数,并且在PHP 7中完全删除了它

More info can be found on the php documentation:

更多信息可以在php文档中找到:

Quote:

引用:

Warning
This extension was deprecated in PHP 5.5.0, and it was removed in PHP 7.0.0. Instead, the MySQLi or PDO_MySQL extension should be used. See also MySQL: choosing an API guide and related FAQ for more information. Alternatives to this function include:
* mysqli_connect()
* PDO::__construct()

警告此扩展在PHP 5.5.0中已弃用,并已在PHP 7.0.0中删除。相反,应该使用MySQLi或PDO_MySQL扩展。另请参阅MySQL:选择API指南和相关的常见问题解答以获取更多信息。此函数的替代方法包括:* mysqli_connect()* PDO :: __ construct()

#3


2  

I had this same problem and had to refer to the php manual which told me the mysql and mysqli extensions require libmysql.dll to load. I searched for it under C:\windows\system32 (windows 7) and could not find, so I downloaded it here and placed it in my C:\windows\system32. I restarted Apache and everything worked fine. Took me 3 days to figure out, hope it helps.

我有同样的问题,不得不参考php手册告诉我mysql和mysqli扩展需要加载libmysql.dll。我在C:\ windows \ system32(windows 7)下搜索它并找不到,所以我在这里下载并将它放在我的C:\ windows \ system32中。我重新启动Apache,一切正常。花了3天时间弄明白,希望它有所帮助。

#4


0  

The Apache module PHP version might for some odd reason not be picking up the php.ini file as the CLI version I'd suggest having a good look at:

Apache模块PHP版本可能出于某些奇怪的原因而没有把php.ini文件作为CLI版本我建议好好看看:

  • Any differences in the .ini files that differ between php -i and phpinfo() via a web page*
  • 通过网页在php -i和phpinfo()之间存在差异的.ini文件中的任何差异*
  • If there are no differences then to look at the permissions of mysql.so and the .ini files but I think that Apache parses these as the root user
  • 如果没有差异则查看mysql.so和.ini文件的权限但我认为Apache以root用户身份解析这些权限

To be really clear here, don't go searching for php.ini files on the file system, have a look at what PHP says that it's looking at

要在这里非常清楚,不要去搜索文件系统上的php.ini文件,看看PHP说它在看什么

#5


0  

How Bout

怎么样

sudo yum install php-mysql

sudo yum安装php-mysql

or

要么

sudo apt-get install php5-mysql

sudo apt-get install php5-mysql

#6


-3  

I had received a similar error message. Think I inadvertently typed "9o" at start of first line of php.ini file. Once I removed that, I no longer received the "fatal error" messages. Hope this helps.

我收到了类似的错误消息。想想我在php.ini文件的第一行开头无意中输入了“9o”。删除后,我不再收到“致命错误”消息。希望这可以帮助。

#7


-4  

The mysql deamon should be running.

mysql deamon应该正在运行。

If not try this:

如果没有试试这个:

#/etc/init.d/mysql start

Or this:

或这个:

#service mysqld start

And if you want to add mysql on boot:

如果你想在启动时添加mysql:

# chkconfig --add mysqld
# chkconfig -- level 235 mysqld on

If yes, and it is still not working try this:

如果是,并且仍然无法正常运行,请尝试以下操作:

Uncomment the following lines in /etc/php/php.ini

取消注释/etc/php/php.ini中的以下行

extension=mysqli.so
extension=mysql.so

And please check your post above '/usr/lib64/php/modules/msql.so'. It should be mysql.so (if it's mistyped ignore it...)

请查看“/usr/lib64/php/modules/msql.so”上面的帖子。应该是mysql.so(如果输入错误则忽略它......)

#1


63  

In case anyone else faces this, it's a case of PHP not having access to the mysql client libraries. Having a MySQL server on the system is not the correct fix. Fix for ubuntu (and PHP 5):

如果其他人都面临这种情况,那就是PHP无法访问mysql客户端库的情况。在系统上安装MySQL服务器不是正确的解决方法。修复ubuntu(和PHP 5):

sudo apt-get install php5-mysql

After installing the client, the webserver should be restarted. In case you're using apache, the following should work:

安装客户端后,应重新启动Web服务器。如果您正在使用Apache,以下应该工作:

sudo service apache2 restart

#2


16  

Keep in mind that as of PHP 5.5.0 the mysql_connect() function is deprecated, and it is completely removed in PHP 7

请记住,从PHP 5.5.0开始,不推荐使用mysql_connect()函数,并且在PHP 7中完全删除了它

More info can be found on the php documentation:

更多信息可以在php文档中找到:

Quote:

引用:

Warning
This extension was deprecated in PHP 5.5.0, and it was removed in PHP 7.0.0. Instead, the MySQLi or PDO_MySQL extension should be used. See also MySQL: choosing an API guide and related FAQ for more information. Alternatives to this function include:
* mysqli_connect()
* PDO::__construct()

警告此扩展在PHP 5.5.0中已弃用,并已在PHP 7.0.0中删除。相反,应该使用MySQLi或PDO_MySQL扩展。另请参阅MySQL:选择API指南和相关的常见问题解答以获取更多信息。此函数的替代方法包括:* mysqli_connect()* PDO :: __ construct()

#3


2  

I had this same problem and had to refer to the php manual which told me the mysql and mysqli extensions require libmysql.dll to load. I searched for it under C:\windows\system32 (windows 7) and could not find, so I downloaded it here and placed it in my C:\windows\system32. I restarted Apache and everything worked fine. Took me 3 days to figure out, hope it helps.

我有同样的问题,不得不参考php手册告诉我mysql和mysqli扩展需要加载libmysql.dll。我在C:\ windows \ system32(windows 7)下搜索它并找不到,所以我在这里下载并将它放在我的C:\ windows \ system32中。我重新启动Apache,一切正常。花了3天时间弄明白,希望它有所帮助。

#4


0  

The Apache module PHP version might for some odd reason not be picking up the php.ini file as the CLI version I'd suggest having a good look at:

Apache模块PHP版本可能出于某些奇怪的原因而没有把php.ini文件作为CLI版本我建议好好看看:

  • Any differences in the .ini files that differ between php -i and phpinfo() via a web page*
  • 通过网页在php -i和phpinfo()之间存在差异的.ini文件中的任何差异*
  • If there are no differences then to look at the permissions of mysql.so and the .ini files but I think that Apache parses these as the root user
  • 如果没有差异则查看mysql.so和.ini文件的权限但我认为Apache以root用户身份解析这些权限

To be really clear here, don't go searching for php.ini files on the file system, have a look at what PHP says that it's looking at

要在这里非常清楚,不要去搜索文件系统上的php.ini文件,看看PHP说它在看什么

#5


0  

How Bout

怎么样

sudo yum install php-mysql

sudo yum安装php-mysql

or

要么

sudo apt-get install php5-mysql

sudo apt-get install php5-mysql

#6


-3  

I had received a similar error message. Think I inadvertently typed "9o" at start of first line of php.ini file. Once I removed that, I no longer received the "fatal error" messages. Hope this helps.

我收到了类似的错误消息。想想我在php.ini文件的第一行开头无意中输入了“9o”。删除后,我不再收到“致命错误”消息。希望这可以帮助。

#7


-4  

The mysql deamon should be running.

mysql deamon应该正在运行。

If not try this:

如果没有试试这个:

#/etc/init.d/mysql start

Or this:

或这个:

#service mysqld start

And if you want to add mysql on boot:

如果你想在启动时添加mysql:

# chkconfig --add mysqld
# chkconfig -- level 235 mysqld on

If yes, and it is still not working try this:

如果是,并且仍然无法正常运行,请尝试以下操作:

Uncomment the following lines in /etc/php/php.ini

取消注释/etc/php/php.ini中的以下行

extension=mysqli.so
extension=mysql.so

And please check your post above '/usr/lib64/php/modules/msql.so'. It should be mysql.so (if it's mistyped ignore it...)

请查看“/usr/lib64/php/modules/msql.so”上面的帖子。应该是mysql.so(如果输入错误则忽略它......)