gpt4 book ai didi

php - 无法在 Windows 7 上使用 PHP 连接到 MySQL

转载 作者:行者123 更新时间:2023-11-29 02:46:32 25 4
gpt4 key购买 nike

我已经在 Windows7 上使用 手动设置了 wamp 服务器Apache 2.4.23、PHP 5.6.29 和 MYSQL Server 5.5 .每次我尝试连接到 MySQL 时,我都会收到错误消息:

fatal error: call to undefined function mysql_connect



我尝试了以下 stackoverflow 解决方案,但找不到任何 libmysql.dll 在 c:\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 = 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)?提前致谢!

最佳答案

您很可能将代码从旧站点复制到新版本的 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:修复您的代码

无论如何,最好的解决方案是升级您的 PHP 代码,使其不使用已弃用的 mysql_connect。 , mysql_query和其他相关的遗留mysql功能。根据代码的大小,这可能是一个短暂或漫长的过程。但是,考虑这样做很重要,因为较旧的 mysql函数有几个安全漏洞,例如 SQL 注入(inject),如果您不花时间升级代码,您的网站可能容易受到黑客攻击。

关于php - 无法在 Windows 7 上使用 PHP 连接到 MySQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41408826/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com