如何在Windows上安装PHP的PDO驱动程序?

时间:2015-12-10 22:03:26

标签: php mysql windows pdo wamp

我在Windows服务器上安装了Apache,PHP 5.6和MySQL 5.7。

在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

(并重启Apache)

但是当我尝试在我的php页面中使用PDO时,它仍然会抛出错误:

Fatal error: Uncaught exception 'PDOException' with message 'could not find driver'

如何安装PDO我需要做什么?

2 个答案:

答案 0 :(得分:4)

在我的apache httpd.conf中我有(注意我已经## remmed out因为它至少花了我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

在上面的文件夹中(见下文)我有这些文件:

 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

在同一个文件夹中,在php.ini文件中,我有以下与pdo相关的块,其中有效的块没有用;

重新删除

;延长= php_pdo_firebird.dll 延长= php_pdo_mysql.dll ;延长= php_pdo_oci.dll 延长= php_pdo_odbc.dll ;延长= php_pdo_pgsql.dll ;延长= php_pdo_sqlite.dll

然后我有一个phpinfo_xyz.php 文件仅用于测试目的(阅读:完成后删除)包含

<?php phpinfo(); ?>

重新启动apache,从浏览器指向文件并注意以下与以下三种类似的块。

enter image description here

...

enter image description here

...

enter image description here

phpinfo()上面的第一张PHP图片中,它是在httpd.conf中获取时间最长的路径。这就是我在本答案中看到错误路径的原因。

所以直到Loaded Configuration File表现得体面才有机会。

祝你好运。这不好玩。一半的问题是有2或4个选项,其中原始下载执行。可悲的是,我觉得我花了2到3个小时。但我并不像你们其他人那么聪明。

答案 1 :(得分:4)

问题是extension_dir指令不能用作相对路径。从extension_dir="ext"更改为extension_dir="c:/phpinstall_path/ext"解决了问题。