2016-12-31 145 views
2

我已经在Windows7上手动设置了一个wamp服务器,使用Apache 2.4.23,PHP 5.6.29和MYSQL Server 5.5。每次我尝试连接到MySQL我得到的错误:无法使用Windows 7上的PHP连接到MySQL

fatal error: call to undefined function mysql_connect

我曾尝试以下解决方案计算器,但在C我找不到任何的libmysql.dll:\ PHP也不复制激活php_mysql.dll从C:\ PHP到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 = [email protected] 
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

[致命错误:调用未定义的函数mysql \ _connect()](http:// stackoverflow。com/questions/10615436/fatal-error-call-to-undefined-function-mysql-connect) – Dez

+0

您是否尝试过使用'mysqli_'连接/查询?你没有发布任何PHP/MySQL代码,所以很难说。 –

+0

我会尽快尝试mysqli_版本的我的代码。所有我尝试使用mysql_connect(“$ host”,“$ username”,“$ password”)以及mysql_select_db(“$ db_name”)的简单连接脚本,这在我部署了wamp服务器的旧版XP机器中效果很好5.2.5 – rosemary

回答

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中进行调整),您仍然可能在错误日志中以及可能在代码输出中获得弃用的函数警告。

enter image description here

解决方案3:修复您的代码,不管上述的

,最好的解决办法是,使其不使用过时的mysql_connectmysql_query等相关遗留升级你的PHP代码mysql函数。根据您的代码的大小,这可能是一个短或漫长的过程。但是,重要的是要考虑这样做,因为较旧的mysql函数有几个安全漏洞,例如SQL注入,如果您没有花时间升级代码,那么您的网站可能容易受到黑客攻击。

+0

*“到7.0之前的东西”* - OP的PHP版本是5.6.29 –

+0

好的,那么您可能仍然会收到有关mysql_connect被弃用的警告。在5.5之前尝试一个版本(如果你打算使用解决方案1并且安全性不是很大的威胁)。 – LStarky

+0

在phpinfo()页面中,它不显示有关MySQL甚至MySQLi的信息。它显示的只是“mysqlnd”。这意味着不会mysqli工作,也就是说,这个PHP版本不支持它? @Larkark – rosemary

相关问题