DB2 connection configuration

QuestionsDB2 connection configuration
Ed K asked 9 years ago

I'm trying to connect to a DB2 (IBM i) database. Can anyone advise how config.php should be setup?

Here is a section of code that I'm using elsewhere that I know is working:

// connect to server…

$db = '*LOCAL' ;
$user = 'PHP_PROD' ;
$pw = '…' ;

$options = array('i5_naming' => DB2_I5_NAMING_ON) ;

if (($dbh = db2_connect($db, $user, $pw, $options)) === false) {
echo 'connection failed.<br>';
echo db2_conn_errormsg().'<br>';

3 Answers
Abu Ghufran answered 9 years ago


I've not tested db2 connection but it should be something like:

$db_conf = array();
$db_conf["type"] = "db2"; // for native php driver
$db_conf["server"] = "";
$db_conf["user"] = "PHP_PROD";
$db_conf["password"] = "…";
$db_conf["database"] = "*LOCAL";

$g = new jqgrid($db_conf);

For DB2_I5_NAMING_ON, you might need to edit:


if ($argDatabasename && empty($argDSN)) {

if (stripos($argDatabasename,'UID=') && stripos($argDatabasename,'PWD=')) $this->_connectionID = db2_connect($argDatabasename,null,null);
else $this->_connectionID = db2_connect($argDatabasename,$argUsername,$argPassword);

In else, you will need to add options param.

Ed K answered 9 years ago

Thanks Abu – this is working now. For any one else working with DB2/i5 (IBM i / iSeries / AS400) here is what I needed to do.

Changed SQL select string in jqgrid_dist.php from:

SELECT a.*,rownum rnum FROM ($V1b1cc7f086b3f074da452bc3129981) a) WHERE …


SELECT a.*, rownumber() over() as rnum FROM ($V1b1cc7f086b3f074da452bc3129981) a) b WHERE …

(changed "rownum" to "rownumber() over()" and added "b" after select end-paren)

And made the following change in lib/inc/adodb/drivers/adodb-db2.inc.php on *both* sides of the IF for I5_NAMING (which searches for a table based on your library list rather than a hardcoded schema):

$options = array('i5_naming' => DB2_I5_NAMING_ON) ;
$this->_connectionID = db2_connect( … ,$options);

Abu Ghufran answered 9 years ago

Thanks for sharing.

Your Answer

11 + 1 =

Login with your Social Id:

OR, enter

Attach code here and paste link in question.
Attach screenshot here and paste link in question.

How useful was this discussion?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate it.

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?