Source for file adodb-odbc_db2.inc.php
Documentation is available at adodb-odbc_db2.inc.php
V4.97 22 Jan 2008 (c) 2000-2008 John Lim (jlim#natsoft.com.my). All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence.
Set tabs to 4 for best viewing.
Latest version is available at http://adodb.sourceforge.net
DB2 data driver. Requires ODBC.
thanks a lot for your help. Today we discovered what
After "playing" a little bit with the php-scripts that try
to connect to the IBM DB2, we set the optional parameter
Cursortype when calling odbc_pconnect(....).
And the exciting thing: When we set the cursor type
to SQL_CUR_USE_ODBC Cursor Type, then
the whole query speed up from 1 till 10 seconds
to 0.2 till 0.3 seconds for 100 records. Amazing!!!
Therfore, PHP is just almost fast as calling the DB2
from Servlets using JDBC (don't take too much care
about the speed at whole: the database was on a
completely other location, so the whole connection
was made over a slow network connection).
I hope this helps when other encounter the same
problem when trying to connect to DB2 from
Mark Newnham has discovered that the SQL_CUR_USE_ODBC is not supported by
IBM's DB2 ODBC driver, so this must be a 3rd party ODBC driver.
From the IBM CLI Reference:
SQL_ATTR_ODBC_CURSORS (DB2 CLI v5)
This connection attribute is defined by ODBC, but is not supported by DB2
CLI. Any attempt to set or get this attribute will result in an SQLSTATE of
HYC00 (Driver not capable).
A 32-bit option specifying how the Driver Manager uses the ODBC cursor
So I guess this means the message [above] was related to using a 3rd party
To set SQL_CUR_USE_ODBC for drivers that require it, do this:
$db = NewADOConnection('odbc_db2');
$db->curMode = SQL_CUR_USE_ODBC;
$db->Connect($dsn, $userid, $pwd);
I have had reports that the $host and $database params have to be reversed in
Connect() when using the CLI interface. From Halmai Csongor csongor.halmai#nexum.hu:
> The symptom is that if I change the database engine from postgres or any other to DB2 then the following
> connection command becomes wrong despite being described this version to be correct in the docs.
> $connection_object->Connect( $DATABASE_HOST, $DATABASE_AUTH_USER_NAME, $DATABASE_AUTH_PASSWORD, $DATABASE_NAME )
> In case of DB2 I had to swap the first and last arguments in order to connect properly.
IF you get a System Error 5 when trying to Connect/Load, it could be a permission problem. Give the user connecting
to DB2 full rights to the DB2 SQLLIB directory, and place the user in the DBUSERS group.
if (!defined('_ADODB_ODBC_LAYER')) {
include(ADODB_DIR. "/drivers/adodb-odbc.inc.php");
// The complete string representation of a timestamp has the form
// yyyy-mm-dd-hh.mm.ss.nnnnnn.
function IfNull( $field, $ifNull )
return " COALESCE($field, $ifNull) "; // if DB2 UDB
//odbc_setoption($this->_connectionID,1,101 /*SQL_ATTR_ACCESS_MODE*/, 1 /*SQL_MODE_READ_ONLY*/);
$vers = $this->GetOne('select versionnumber from sysibm.sysversions');
//odbc_setoption($this->_connectionID,1,101, 0 /*SQL_MODE_READ_WRITE*/);
return array('description'=> 'DB2 ODBC driver', 'version'=> $vers);
function RowLock($tables,$where,$flds= '1 as ignore')
return $this->GetOne("select $flds from $tables where $where for update");
function &MetaTables($ttype= false,$showSchema= false, $qtable= "%", $qschema= "%")
global $ADODB_FETCH_MODE;
$savem = $ADODB_FETCH_MODE;
$ADODB_FETCH_MODE = $savem;
$isview = strncmp($ttype,'V',1) === 0;
for ($i= 0; $i < sizeof($arr); $i++ ) {
if (!$arr[$i][2]) continue;
if (strncmp($arr[$i][1],'SYS',3) === 0) continue;
if ($showSchema) $arr[$i][2] = $arr[$i][1]. '.'. $arr[$i][2];
if (strncmp($type,'V',1) === 0) $arr2[] = $arr[$i][2];
} else if (strncmp($type,'T',1) === 0) $arr2[] = $arr[$i][2];
} else if (strncmp($type,'S',1) !== 0) $arr2[] = $arr[$i][2];
function &MetaIndexes ($table, $primary = FALSE, $owner= false)
global $ADODB_FETCH_MODE;
$save = $ADODB_FETCH_MODE;
$SQL= "SELECT NAME, UNIQUERULE, COLNAMES FROM SYSIBM.SYSINDEXES WHERE TBNAME='$table'";
$SQL.= " AND UNIQUERULE='P'";
$ADODB_FETCH_MODE = $save;
// parse index data into array
while ($row = $rs->FetchRow()) {
$indexes[$row[0]] = array(
'unique' => ($row[1] == 'U' || $row[1] == 'P'),
$cols = ltrim($row[2],'+');
$indexes[$row[0]]['columns'] = explode('+', $cols);
$ADODB_FETCH_MODE = $save;
// Format date column in sql string given an input format that understands Y M D
// use right() and replace() ?
for ($i= 0; $i < $len; $i++ ) {
$s .= "char(year($col))";
$s .= "substr(monthname($col),1,3)";
$s .= "right(digits(month($col)),2)";
$s .= "right(digits(day($col)),2)";
if ($col != $this->sysDate) $s .= "right(digits(hour($col)),2)";
$s .= "right(digits(minute($col)),2)";
$s .= "right(digits(second($col)),2)";
function &SelectLimit($sql,$nrows=- 1,$offset=- 1,$inputArr= false)
$nrows = (integer) $nrows;
// could also use " OPTIMIZE FOR $nrows ROWS "
if ($nrows >= 0) $sql .= " FETCH FIRST $nrows ROWS ONLY ";
$rs = & $this->Execute($sql,$inputArr);
if ($offset > 0 && $nrows < 0);
$sql .= " FETCH FIRST $nrows ROWS ONLY ";
function MetaType($t,$len=- 1,$fieldobj= false)
$len = $fieldobj->max_length;
if ($len <= $this->blobSize) return 'C';
case 'DBCLOB': // double-byte
|