ODBC and DB2 Functions (PDO_ODBC)

Introduction

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 database servers through the unixODBC driver
manager and the database's own ODBC drivers.

generic

Offers a compile option for ODBC driver managers that are not
explicitly supported by PDO_ODBC.

On Windows, PDO_ODBC is built into the PHP core by default. 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.

Installation

PDO_ODBC on UNIX systems

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.

ibm_db2

./configure --with-pdo-odbc=ibm-db2,/opt/IBM/db2/V8.1/

To build PDO_ODBC with the ibm-db2 flavour, you have to have
previously installed the DB2 application development headers on the
same machine on which you are compiling PDO_ODBC. The DB2 application
development headers are an installable option in the DB2 servers, and
are also available as part of the DB2 Application Development Client
freely available for download from the IBM DB2 Universal Database
» support site.

If you do not supply a location for the DB2 libraries and headers to
the configure command, PDO_ODBC defaults to
/home/db2inst1/sqllib.

unixODBC

./configure --with-pdo-odbc=unixODBC,/usr/local

If you do not supply a location for the unixODBC libraries and
headers to the configure command, PDO_ODBC
defaults to /usr/local.

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.

Warning

relaxed matching should not be used on a shared
server, for security reasons.

Tip

Leave this setting at the default strict setting
unless you have good reason to change it.

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.

Using SQL 2005, PDO_ODBC and datetime fields is a royal pain. MSDN documentation on CAST CONVERT shows that there is supposed to be an implicit convert between character types and datetime types. That's true... until you put it in a stored procedure and use variable declarations.

If you want to avoid installing DB2 Connect and/or PECL modules ibm_db2 and PDO_IBM, you can also use IBM DB2 databases trough unixODBC.

If you have DB2 database on a i server you need to install IBM iAccess (http://www.ibm.com/systems/i/software/access/linux/index.html) and unixODBC. Just install the libraries (rpm) and modify configurations in /etc/odbcinst.ini (sample configuration in /opt/ibm/iSeriesAccess/unixodbcregistration) and /etc/odbc.ini.