windows 如何在 PHP 中安装 MySQL 模块?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/158279/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I install MySQL modules within PHP?
提问by Zack Peterson
I've updated php.iniand moved php_mysql.dllas explained in steps 6 and 8 here.
我已经更新了php.ini并移动了php_mysql.dll,如此处第6 步和第 8 步所述。
I get this error…
我收到此错误...
Fatal error: Call to undefined function mysql_connect() in C:\inetpub...
MySQL doesn't show up in my phpinfo;report.
MySQL 没有出现在我的phpinfo 中;报告。
I've updated the c:\Windows\php.inifile from
我已经更新了c:\Windows\php.ini文件
; Directory in which the loadable extensions (modules) reside. extension_dir = "./"
to
到
; Directory in which the loadable extensions (modules) reside. extension_dir = ".;c:\Windows\System32"
Result: no change.
结果:没有变化。
I changed the php.inivalue of extension_dir thusly:
我这样更改了extension_dir的php.ini值:
extension_dir = "C:\Windows\System32"
Result: much more in the phpinfo;report, but MySQL still isn't working.
结果:在phpinfo 中有更多内容;报告,但 MySQL 仍然无法正常工作。
I copied the file libmysql.dllfrom folder C:\phpto folders C:\Windows\System32and C:\Windows
我将文件libmysql.dll从文件夹C:\php复制到文件夹C:\Windows\System32和C:\Windows
Result: no change.
结果:没有变化。
I stopped and restarted IIS.
我停止并重新启动 IIS。
Result: new, different errors instead!
结果:新的、不同的错误!
Warning: mysql_connect() [function.mysql-connect]: Access denied for user '...'@'localhost' (using password: YES) in C:\inetpub\... error in query.
Fatal error: Call to a member function RecordCount() on a non-object in C:\inetpub\...
I found several .php files in the website where I had to set variables:
我在网站上发现了几个 .php 文件,我必须在其中设置变量:
$db_user $db_pass
Result: The site works!
结果:网站正常运行!
回答by Richard Harrison
As the others say these two values in php.ini are crucial.
正如其他人所说,php.ini 中的这两个值至关重要。
I have the following in my php.ini: note the trailing slash - not sure if it is needed - but it does work.
我的 php.ini 中有以下内容:注意尾部斜杠 - 不确定是否需要 - 但它确实有效。
extension_dir = "H:\apps\php\ext\"
extension=php_mysql.dll
Also it is worth ensuring that you only have one copy of php.ini on your machine - I've had problems with this where I've been editting a php.ini file which php isn't using and getting very frustrated until I realised.
同样值得确保您的机器上只有一份 php.ini 副本 - 我遇到了这个问题,我一直在编辑一个 php.ini 文件,而该文件没有使用 php 并且在我意识到之前感到非常沮丧.
Also if php is running as a module within apache you will need to restart the apache server to pickup the changes. Wise to do this in anycase if you're not sure.
此外,如果 php 作为 apache 中的一个模块运行,您将需要重新启动 apache 服务器以获取更改。如果您不确定,无论如何最好这样做。
a "php -m" from the cmd prompt will show you the modules that are loaded from the ini file.
cmd 提示符中的“php -m”将显示从 ini 文件加载的模块。
回答by vIceBerg
In the php.ini file, check if the extention path configuration is valid.
在 php.ini 文件中,检查扩展路径配置是否有效。
回答by Harrison Fisk
You will need to enable the extension=php_mysql.dll option in the php.ini as well. Also, make sure that the file is in the extension_dir you set.
您还需要在 php.ini 中启用 extension=php_mysql.dll 选项。另外,请确保该文件位于您设置的 extension_dir 中。
You can read more about it at:
您可以在以下位置阅读更多信息:
回答by leek
On a completely different note, might I suggest WampServer? It should get you up and running with a Apache/PHP/MySQL install in no time.
在一个完全不同的注释中,我可以建议WampServer吗?它应该可以让您立即启动并运行 Apache/PHP/MySQL 安装。
You could even compare the WampServer config files with your own to see where you originally went wrong.
您甚至可以将 WampServer 配置文件与您自己的配置文件进行比较,以查看您最初出错的地方。