我在Windows7上手动设置了wamp服务器,其中包含 Apache 2.4.23,PHP 5.6.29和MYSQL Server 5.5 。每次我尝试连接MySQL时都会收到错误:
致命错误:调用未定义函数mysql_connect
我尝试过以下stackoverflow解决方案,但我在c:\ PHP中找不到任何 libmysql.dll ,也没有从c:\ PHP复制 php_mysql.dll C:\ Windows \ System32很有成效: Call to undefined function mysql_connect
我phpinfo()
的输出:
https://jsfiddle.net/ad0gd90y/
我还查看了Apache中的错误日志文件:
Installing Apache HTTP Server 2.x with
DomainName = example.com
ServerName = www.example.com
ServerAdmin = admin@example.com
ServerPort = 80
ServerSslPort = 443
ServerRoot = c:/Apache24
Rewrote docs/conf/extra/httpd-autoindex.conf.in
to c:/Apache24/conf/original/extra/httpd-autoindex.conf
Rewrote docs/conf/extra/httpd-default.conf.in
to c:/Apache24/conf/original/extra/httpd-default.conf
Rewrote docs/conf/extra/httpd-ssl.conf.in
to c:/Apache24/conf/original/extra/httpd-ssl.conf
Rewrote docs/conf/extra/httpd-multilang-errordoc.conf.in
to c:/Apache24/conf/original/extra/httpd-multilang-errordoc.conf
Rewrote docs/conf/extra/httpd-info.conf.in
to c:/Apache24/conf/original/extra/httpd-info.conf
Rewrote docs/conf/extra/httpd-userdir.conf.in
to c:/Apache24/conf/original/extra/httpd-userdir.conf
Rewrote docs/conf/extra/httpd-mpm.conf.in
to c:/Apache24/conf/original/extra/httpd-mpm.conf
Rewrote docs/conf/httpd.conf.in
to c:/Apache24/conf/original/httpd.conf
Rewrote docs/conf/extra/proxy-html.conf.in
to c:/Apache24/conf/original/extra/proxy-html.conf
Rewrote docs/conf/extra/httpd-vhosts.conf.in
to c:/Apache24/conf/original/extra/httpd-vhosts.conf
Rewrote docs/conf/extra/httpd-dav.conf.in
to c:/Apache24/conf/original/extra/httpd-dav.conf
Rewrote docs/conf/extra/httpd-languages.conf.in
to c:/Apache24/conf/original/extra/httpd-languages.conf
Rewrote docs/conf/extra/httpd-manual.conf.in
to c:/Apache24/conf/original/extra/httpd-manual.conf
Duplicated c:/Apache24/conf/original/extra/httpd-autoindex.conf
to c:/Apache24/conf/extra/httpd-autoindex.conf
Duplicated c:/Apache24/conf/original/extra/httpd-default.conf
to c:/Apache24/conf/extra/httpd-default.conf
Duplicated c:/Apache24/conf/original/extra/httpd-ssl.conf
to c:/Apache24/conf/extra/httpd-ssl.conf
Duplicated c:/Apache24/conf/original/extra/httpd-multilang-errordoc.conf
to c:/Apache24/conf/extra/httpd-multilang-errordoc.conf
Duplicated c:/Apache24/conf/original/extra/httpd-info.conf
to c:/Apache24/conf/extra/httpd-info.conf
Duplicated c:/Apache24/conf/original/extra/httpd-userdir.conf
to c:/Apache24/conf/extra/httpd-userdir.conf
Duplicated c:/Apache24/conf/original/extra/httpd-mpm.conf
to c:/Apache24/conf/extra/httpd-mpm.conf
Duplicated c:/Apache24/conf/original/httpd.conf
to c:/Apache24/conf/httpd.conf
Duplicated c:/Apache24/conf/original/magic
to c:/Apache24/conf/magic
Duplicated c:/Apache24/conf/original/charset.conv
to c:/Apache24/conf/charset.conv
Duplicated c:/Apache24/conf/original/extra/proxy-html.conf
to c:/Apache24/conf/extra/proxy-html.conf
Duplicated c:/Apache24/conf/original/extra/httpd-vhosts.conf
to c:/Apache24/conf/extra/httpd-vhosts.conf
Duplicated c:/Apache24/conf/original/extra/httpd-dav.conf
to c:/Apache24/conf/extra/httpd-dav.conf
Duplicated c:/Apache24/conf/original/mime.types
to c:/Apache24/conf/mime.types
Duplicated c:/Apache24/conf/original/extra/httpd-languages.conf
to c:/Apache24/conf/extra/httpd-languages.conf
Duplicated c:/Apache24/conf/original/extra/httpd-manual.conf
to c:/Apache24/conf/extra/httpd-manual.conf
我对如何解决这个问题完全无能为力。还有什么是libmysql.dll用于?是否有任何安装顺序可以完成(我最后安装了apache,然后是php和mysql)?提前谢谢!
答案 0 :(得分:1)
您很可能将代码从旧网站复制到较新版本的PHP。代码mysql_connect
在PHP 5.5中已弃用,在PHP 7.0中已删除。您还需要确保PHP是使用MySQL支持编译的。
解决方案1:检查MySQL支持
Detecting mysql support in php
使用上面的链接确定PHP是否是使用MySQL支持编译的。如果不是,那么继续使用适当的支持(PDO和MySQL)重新安装PHP或WAMP。
解决方案2:降级PHP
如果问题与mysql_connect
和相关的mysql_
函数有关,则可以通过调整其使用的版本将WAMP安装中的PHP版本更改为早于7.0的版本在工具栏中的设置中。请注意,对于介于5.5和7.0之间的版本,您可能仍会在错误日志中以及可能在代码输出中获得已弃用的功能警告,具体取决于您显示的错误(可在php.ini中调整) )。
解决方案3:修复您的代码
无论上述情况如何,最佳解决方案是升级PHP代码,使其不使用已弃用的mysql_connect
,mysql_query
和其他相关的旧版mysql函数。根据代码的大小,这可能是一个简短或漫长的过程。但是,考虑这样做很重要,因为较旧的mysql
函数存在多个安全漏洞,例如SQL注入,如果您不花时间,您的网站可能容易遭受黑客攻击升级您的代码。