如何在 Windows 上为 PHP 安装 PDO 驱动程序?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34212578/
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 PDO drivers for PHP on Windows?
提问by Don Rhummy
I installed Apache, PHP 5.6 and MySQL 5.7 on a Windows server.
我在 Windows 服务器上安装了 Apache、PHP 5.6 和 MySQL 5.7。
In php.ini, I enabled the following:
在 php.ini 中,我启用了以下内容:
extension=php_mysql.dll
extension=php_mysqli.dll
extension=php_oci8_12c.dll
extension=php_pdo_mysql.dll
extension=php_pdo_oci.dll
(And restarted Apache)
(并重新启动Apache)
But when I try to use PDO in my php page, it still throws the error:
但是当我尝试在我的 php 页面中使用 PDO 时,它仍然抛出错误:
Fatal error: Uncaught exception 'PDOException' with message 'could not find driver'
What do I have to do to get PDO installed?
我需要做什么才能安装 PDO?
回答by Don Rhummy
The problem was the extension_dir
directive did not work as a relative path. Changing from extension_dir="ext"
to extension_dir="c:/phpinstall_path/ext"
fixed the problem.
问题是该extension_dir
指令不能用作相对路径。更改extension_dir="ext"
为extension_dir="c:/phpinstall_path/ext"
解决了问题。
回答by Drew
In my apache httpd.conf
I have (note I have # as remmed out because it took me 1 hour at least). So I left it to show me how notto do it.
在我的 apache 中httpd.conf
我有(注意我有 # as remmed,因为它至少花了我 1 小时)。所以我留下它来告诉我如何不这样做。
#PHPIniDir 'c:\apps\php\'
#PHPIniDir "C:\Apache24\~PHP_download\php-5.6.11-Win32-VC11-x64\"
PHPIniDir "C:/Apache24/~PHP_download/php-5.6.11-Win32-VC11-x64"
#LoadModule php5_module "c:/apps/php/php5apache2_2.dll"
LoadModule php5_module "C:/Apache24/~PHP_download/php-5.6.11-Win32-VC11-x64/php5apache2_4.dll"
AddHandler application/x-httpd-php .php
In the above folder (and seen below) I have these files:
在上面的文件夹中(如下所示),我有这些文件:
Directory of C:\Apache24\~PHP_download\php-5.6.11-Win32-VC11-x64
07/24/2015 12:33 PM <DIR> .
07/24/2015 12:33 PM <DIR> ..
07/24/2015 12:32 PM 69,632 deplister.exe
07/24/2015 12:32 PM <DIR> dev
07/24/2015 12:32 PM <DIR> ext
07/24/2015 12:32 PM <DIR> extras
07/24/2015 12:32 PM 1,290,752 glib-2.dll
07/24/2015 12:32 PM 16,384 gmodule-2.dll
07/24/2015 12:32 PM 25,337,856 icudt54.dll
07/24/2015 12:32 PM 1,907,712 icuin54.dll
07/24/2015 12:32 PM 51,200 icuio54.dll
07/24/2015 12:32 PM 256,000 icule54.dll
07/24/2015 12:32 PM 50,176 iculx54.dll
07/24/2015 12:32 PM 63,488 icutest54.dll
07/24/2015 12:32 PM 195,072 icutu54.dll
07/24/2015 12:32 PM 1,369,088 icuuc54.dll
07/24/2015 12:32 PM 79,826 install.txt
07/24/2015 12:32 PM <DIR> lib
07/24/2015 12:32 PM 1,823,232 libeay32.dll
07/24/2015 12:32 PM 46,592 libenchant.dll
07/24/2015 12:32 PM 160,256 libpq.dll
07/24/2015 12:32 PM 237,056 libsasl.dll
07/24/2015 12:32 PM 201,728 libssh2.dll
07/24/2015 12:32 PM 3,286 license.txt
07/24/2015 12:32 PM 518,643 news.txt
07/24/2015 12:32 PM 43 phar.phar.bat
07/24/2015 12:32 PM 53,242 pharcommand.phar
07/24/2015 12:32 PM 58,368 php-cgi.exe
07/24/2015 12:32 PM 30,720 php-win.exe
07/24/2015 12:32 PM 77,824 php.exe
07/24/2015 12:32 PM 2,523 php.gif
08/29/2015 02:28 PM 74,572 php.ini
07/24/2015 12:32 PM 74,334 php.ini-development
07/24/2015 12:32 PM 74,365 php.ini-production
07/24/2015 12:32 PM 31,744 php5apache2_4.dll
07/24/2015 12:32 PM 845,830 php5embed.lib
07/24/2015 12:32 PM 167,936 php5phpdbg.dll
07/24/2015 12:32 PM 8,269,312 php5ts.dll
07/24/2015 12:32 PM 180,224 phpdbg.exe
07/24/2015 12:32 PM 21,360 readme-redist-bins.txt
07/24/2015 12:32 PM 3,634 snapshot.txt
07/24/2015 12:32 PM 353,280 ssleay32.dll
And in that same folder, in the php.ini file I have the following block that are pdo-related, with the ones in force not remmed out with a ;
在同一个文件夹中,在 php.ini 文件中,我有以下与 pdo 相关的块,其中有效的块没有用 ;
;extension=php_pdo_firebird.dll extension=php_pdo_mysql.dll ;extension=php_pdo_oci.dll extension=php_pdo_odbc.dll ;extension=php_pdo_pgsql.dll ;extension=php_pdo_sqlite.dll
;extension=php_pdo_firebird.dll extension=php_pdo_mysql.dll ;extension=php_pdo_oci.dll extension=php_pdo_odbc.dll ;extension=php_pdo_pgsql.dll ;extension=php_pdo_sqlite.dll
then I have a phpinfo_xyz.php
filefor testing purposes only (read: delete it when you are done) that contains
那么我有一个仅用于测试目的的phpinfo_xyz.php
文件(阅读:完成后删除它),其中包含
<?php phpinfo(); ?>
Restart apache, point to that filefrom a browser and notice the following blocks similar to the following three.
重新启动 apache,从浏览器指向该文件并注意以下与以下三个类似的块。
...
...
...
...
In the first PHP picture above from phpinfo()
, it was the getting the path right in httpd.conf that took the longest. That is why I left in the wrong path attempts seen in this Answer.
在上面的第一张 PHP 图片中,phpinfo()
在 httpd.conf 中获取正确路径花费的时间最长。这就是为什么我在这个答案中看到的错误路径尝试。
So it wasn't until Loaded Configuration File
showed up decent that it had a chance.
所以直到Loaded Configuration File
出现体面的时候,它才有机会。
Good luck. It was not fun. Half the problem was there were like 2 or 4 options of which original download to perform. Sadly I think it took me 2 or 3 hours all together. But I am not as smart as the rest of you.
祝你好运。这不好玩。一半的问题是有 2 或 4 个选项可以执行原始下载。可悲的是,我认为我总共花了 2 或 3 个小时。但我没有你们其他人那么聪明。