PHP 7.1.5 Released


在 Unix 系统上安装 PDO
  1. 自 PHP 5.1.0 起,PDO 和 PDO_SQLITE 驱动默认可用。对于自己选择的数据库,需要启用相应的 POD 驱动; 查阅 特定数据库的 PDO 驱动 文档获取更多此内容。


    当以共享扩展(不推荐)构建 PDO 时,所有 PDO 驱动 必须 在 PDO 自身 之后 加载。

  2. 当作为一个共享模块安装 PDO 时,需要更新 php.ini 文件以便当 PHP 运行时 PDO 扩展能被自动加载。还需要在那里启用具体的数据库驱动;确保它们被列在 那一行之后,因为 PDO 必须在具体的 数据库扩展被载入前初始化。如果静态地构建 PDO 和 具体数据库扩展,可以跳过此步。

Windows 用户
  1. PDO 和所有主要的驱动作为共享扩展随 PHP 一起发布,要激活它们只需简单地编辑 php.ini 文件:



    这一步在 PHP 5.3及更高版本中不是必须的,对于 PDO 不再需要做为一个 DLL 文件。

  2. 下一步,选择其他具体数据库的 DLL 文件,然后要么在运行时用 dl() 载入,要么在 php.ini 中的 php_pdo.dll 后面启用。例如:


    那些 DLL 文件应该在系统的extension_dir 中存在。


记住:更改 php.ini 文件后需要重启 PHP 服务才能使新的配置指令生效。

add a note add a note

User Contributed Notes 4 notes

jean dot ferreira at gmail dot com
3 years ago
==Installation pdo_ibm in PHP5, using Data Server Driver Package on Debian / Ubuntu==

#You do not need DB2 (database) installed

#1- Install packages
apt-get install ksh, php5-dev

#2- Make directory
mkdir /opt/ibm

#3- Download Data Server Driver Package (dsdriver), as the architecture

#4- Decompress dsdriver at /opt/ibm/
tar -xvf v10.5fp1_linuxx64_dsdriver.tar.gz  (linux64)
tar -xvf v10.5fp1_linuxia32_dsdriver.tar.gz (linux32)

#5- Change permission -  /opt/ibm/dsddriver and run the installation script
chmod 755 installDSDriver
ksh installDSDriver

#6 Download the PDO IBM driver from and untar the file
tar -xvf PDO_IBM-1.3.3.tgz

#7 Change to the PDO_IBM-1.3.3 directory (that contains the config.m4 file) and execute 'phpize'
cd /xxxx/PDO_IBM-1.3.3

#8 Configure, make and make install
./configure --with-pdo-ibm=/opt/ibm/dsdriver/lib
make install

#9- Change php.ini
vim /etc/php5/apache2/php.ini
; Dynamic Extensions ;
extension =

#10- Reboot the Apache
service apache2 restart
1 year ago
If you do need to install because your distribution does not include it by default (for example PHP 5.5 on Centos), use

yum install php-pdo
7 years ago
This page states
"You may need to enable the PDO driver for your database of choice; consult the documentation for [database-specific PDO drivers]  to find out more about that."

With the term "database-specific PDO drivers" being a link to this information. However you will no find this information on that or any of the pages that it in turn links to.

The appropriate config options seems to be only available by running ./config --help from the source directory after running autoconf.

Here is the related output from running that command:
  --with-pdo-dblib[=DIR]    PDO: DBLIB-DB support.  DIR is the FreeTDS home directory
  --with-pdo-firebird[=DIR] PDO: Firebird support.  DIR is the Firebird base
                            install directory [/opt/firebird]
  --with-pdo-mysql[=DIR]    PDO: MySQL support. DIR is the MySQL base directoy
                                 If mysqlnd is passed as DIR, the MySQL native
                                 native driver will be used [/usr/local]
  --with-zlib-dir[=DIR]       PDO_MySQL: Set the path to libz install prefix
  --with-pdo-oci[=DIR]      PDO: Oracle OCI support. DIR defaults to $ORACLE_HOME.
                            Use --with-pdo-oci=instantclient,prefix,version
                            for an Oracle Instant Client SDK.
                            For Linux with RPMs (for example) use:
                            PDO: Support for 'flavour' ODBC driver.
                            include and lib dirs are looked for under 'dir'.
                            'flavour' can be one of:  ibm-db2, iODBC, unixODBC, generic
                            If ',dir' part is omitted, default for the flavour
                            you have selected will used. e.g.:
                            will check for unixODBC under /usr/local. You may attempt
                            to use an otherwise unsupported driver using the "generic"
                            flavour.  The syntax for generic ODBC support is:

                            When build as shared the extension filename is always
  --with-pdo-pgsql[=DIR]    PDO: PostgreSQL support.  DIR is the PostgreSQL base
                            install directory or the path to pg_config
                            PDO: sqlite 3 support.  DIR is the sqlite base
                            install directory [BUNDLED]

So if you wish for instance to install the PostgreSQL PDO driver, then you should add the --with-pdo-pgsql config option before compiling PHP. I may have made mistakes in my explination, however it appears to work and was my best guess given the absence of the mentioned documentation.
dtcwee at hotmail dot com
6 years ago
You may receive this error when testing a PDO-ODBC connection:

"The specified DSN contains an architecture mismatch between the Driver and Application"

My environment was Windows 7 (64 bit), MySQL ODBC drivers (64 bit), Apache 2.2.17 (32 bit), PHP 5.3.5 (32 bit).

If you are like me, you were testing the PDO-ODBC connection because the native database drivers were not visible to PHP. Furthermore, the MySQL 32 bit drivers did not work in my environment.

Solution: Your environment has to be 64 bit all the way through.

Install 64 bit versions of Apache and PHP. They are not available from official sources. However, kind people have compiled some and made them available for download.

As a bonus, the native database drivers suddenly showed up enabled.
To Top