PDO_ODBC is a driver that implements the PHP Data Objects (PDO) interface to enable access from PHP to databases through ODBC drivers or through the IBM DB2 Call Level Interface (DB2 CLI) library. PDO_ODBC currently supports three different "flavours" of database drivers:
Supports access to IBM DB2 Universal Database, Cloudscape, and Apache Derby servers through the free DB2 express-C client.
Supports access to database servers through the unixODBC driver manager and the database's own ODBC drivers.
Offers a compile option for ODBC driver managers that are not explicitly supported by PDO_ODBC.
On Windows, php_pdo_odbc.dll has to be enabled as extension in php.ini. It is linked against the Windows ODBC Driver Manager so that PHP can connect to any database cataloged as a System DSN, and is the recommended driver for connecting to Microsoft SQL Server databases.
As of PHP 5.1, PDO_ODBC is included in the PHP source. You can compile the PDO_ODBC extension as either a static or shared module using the following configure commands.
./configure --with-pdo-odbc=ibm-db2,/opt/IBM/db2/V8.1/
If you do not supply a location for the DB2 libraries and headers to the configure command, PDO_ODBC defaults to /home/db2inst1/sqllib.
./configure --with-pdo-odbc=unixODBC,/usr/local
./configure --with-pdo-odbc=generic,/usr/local,libname,ldflags,cflags
下列常量由此驱动定义,且仅在扩展编译入 PHP
或在运行时动态载入时可用。另外,使用此驱动时,仅会使用这些驱动特定的常量。使用其他驱动的驱动特定的常量可能会导致不可预见的情况。如果代码可运行于多个驱动,PDO::getAttribute()
可被用于获取
PDO_ATTR_DRIVER_NAME
属性以检查驱动。
PDO::ODBC_ATTR_USE_CURSOR_LIBRARY
(integer)
This option controls whether the ODBC cursor library is used. The ODBC cursor library supports some advanced ODBC features (e.g. block scrollable cursors), which may not be implemented by the driver. The following values are supported:
PDO::ODBC_SQL_USE_IF_NEEDED
(the default):
use the ODBC cursor library when needed.
PDO::ODBC_SQL_USE_DRIVER
:
never use the ODBC cursor library.
PDO::ODBC_SQL_USE_ODBC
:
always use the ODBC cursor library.
PDO::ODBC_ATTR_ASSUME_UTF8
(boolean)
Windows only. If TRUE
, UTF-16 encoded character data (CHAR,
VARCHAR and LONGVARCHAR) is converted to
UTF-8 when reading from or writing data to the database.
If FALSE
(the default), no character encoding conversion is done.
这些函数的行为受 php.ini 中的设置影响。
名字 | 默认 | 可修改范围 | 更新日志 |
---|---|---|---|
pdo_odbc.connection_pooling | "strict" | PHP_INI_ALL | Available since PHP 5.1.0. |
pdo_odbc.db2_instance_name | NULL | PHP_INI_SYSTEM | Available since PHP 5.1.1. 本过时特性将肯定会在未来被移除。 |
这是配置指令的简短说明。
pdo_odbc.connection_pooling
string
Whether to pool ODBC connections. Can be one of "strict",
"relaxed" or "off" (equals to
""). The parameter describes how strict the connection
manager should be when matching connection parameters to existing pooled
connections. strict
is the recommend default, and
will result in the use of cached connections only when all the connection
parameters match exactly. relaxed
will result in
the use of cached connections when similar connection parameters are
used. This can result in increased use of the cache, at the risk of
bleeding connection information between (for example) virtual hosts.
This setting can only be changed from the php.ini file, and affects the entire process; any other modules loaded into the process that use the same ODBC libraries will be affected too, including the Unified ODBC extension.
relaxed
matching should not be used on a shared
server, for security reasons.
Leave this setting at the default strict
setting
unless you have good reason to change it.
pdo_odbc.db2_instance_name
string
If you compile PDO_ODBC using the db2 flavour, this setting sets the value of the DB2INSTANCE environment variable on Linux and UNIX operating systems to the specified name of the DB2 instance. This enables PDO_ODBC to resolve the location of the DB2 libraries and make cataloged connections to DB2 databases.
This setting can only be changed from the php.ini file, and affects the entire process; any other modules loaded into the process that use the same ODBC libraries will be affected too, including the Unified ODBC extension.
This setting has no effect on Windows.