DB2 Connect Strings for PHP

General discussion on Zend Server for IBM System i
Post Reply
Posts: 3
Joined: Mon Mar 07, 2011 9:13 pm

DB2 Connect Strings for PHP

Post by bpiotrowski » Mon Mar 07, 2011 9:16 pm

Hi All,

Does anyone have any code samples that demonstrates the connection to a DB2 database and the retrieval / display of some data?

For example, on our iSeries, I have my data library under DEVDATA. If I create a new table called MYNAMES with field names of record_id (int), name (varchar(50)) and myage (int), how would I write a small program to retrieve and display the data from the table?

We're going to be converting all of our ASP pages to PHP soon, but I need to understand how to access the database. In ASP, it was simply an ODBC connection back to the table, but I am unsure what I need to do for PHP.

Thanks in advance.

Posts: 13
Joined: Wed Dec 15, 2010 2:18 pm

Re: DB2 Connect Strings for PHP

Post by bpeeters » Tue Mar 08, 2011 9:28 am

Try this:

Code: Select all

$constrng = 'odbc:dsn-name';
$conn = new PDO($constrng,'username','password');

Posts: 7
Joined: Thu Jan 06, 2011 8:54 pm

Re: DB2 Connect Strings for PHP

Post by joewhitlock » Thu Mar 17, 2011 10:18 pm

Try Conn = db2_connect(Server, Userid, Password)

Posts: 158
Joined: Mon Mar 23, 2009 5:22 pm

Re: DB2 Connect Strings for PHP

Post by zend_i5 » Wed Mar 23, 2011 3:54 pm

You can find PHP code samples (including connection to DB) in the Zend Server installation directory:
or run the following link which will run and display PHP code samples:

Post Reply