ADOdb

Database Abstraction Layer for PHP

User Tools

Site Tools


v6:database:ibm_db2

IBM DB2

Specification
Driver Namedb2
Data Providerdb2
StatusActive1)
WindowsYes
UnixYes
DSN SupportYes
Alternative Drivers

ODBC Driver For IBM DB2

Description

This driver provides a connection to IBM DB2 Databases, using the IBM Data Client. This driver replaces the original DB2 ODBC driver.

PHP Drivers For Windows

PHP 7 drivers for windows are currently available here



Connection Example Using Instance

The DB2 database must be catalogued for a connection like this to work.

$acd = new ADOdb\ADOConnectionDefinitions;
 
$dbParameters = array(
  'database' => 'SAMPLE',
  'user' => 'db2inst1',
  'password' => 'instance'
  );
 
$acd->dbParameters = $dbParameters;
 
$obj = new ADOdb\connector($acd);
 
$db = $obj->connect;

Connection Example Using DSN

$acd = new ADOdb\ADOConnectionDefinitions;
 
$dsn = 'hostname=192.168.0.30;protocol=tcpip;port=50000;database=SAMPLE;uid=db2inst1;pwd=instance';
 
$acd->dsnParameters = $dsn;
 
$obj = new ADOdb\connector($acd);
 
$db = $obj->connect();

Connection Example Using DSN (No Stored Password)

$acd = new ADOdb\ADOConnectionDefinitions;
 
$dsn = 'hostname=192.168.0.30;protocol=tcpip;port=50000;database=SAMPLE;uid=db2inst1;';
 
$acd->dsnParameters = $dsn;
 
$obj = new ADOdb\connector($acd);
 
$db = $obj->connect(null,null,'instance');

Case Sensitivity In Table And Column Names

Unlike most DBMS, DB2 provides complete control over the casing of table and column names. This means, for example, that the tables ACCOUNTS, accounts and Accounts can exist simultaneously in the same database.

In normal usage, table and column names can be searched in a case insensitive manner. That insensitivity always applies precedence to the upper case table name. In this example, 2 tables exist: ACCOUNTS and accounts.

$sql = 'SELECT * FROM ACCOUNTS';
 
$sql = 'SELECT * FROM accounts';
 
/*
* Both of these queries will query the ACCOUNTS table
*/

In order to query the accounts table, it will be necessary to modify the SQL statement, using double quotes

$sql = 'SELECT * FROM "accounts"'

Query Precedence

The following order of query precedence applies:

  1. If a single table name exists in a database, the table can be queried in any way as long as the table name is not quoted
  2. If a single table name exists in a database, a query must match the casing of the name if the query table name is quoted
  3. If multiple tables with the same name apply, any unquoted query will search a table name with upper casing, no matter how the query table name is constructed.

Table Names With Special Characters

Any table name containing special characters will need to be quoted in all queries.

1)
This driver is actively supported by ADOdb project members
v6/database/ibm_db2.txt · Last modified: by 127.0.0.1