How to Query IBM i Data with PHP and PDO_ODBC

ODBC & Db2 for iOf the PHP extensions that can connect to IBM i Db2, PDO_ODBC is the most flexible.

Although the classic extensions (ibm_db2, PDO_IBM) often provide the best performance and integration, PDO_ODBC does have several benefits:

  • PDO_ODBC supports many databases and PHP frameworks
  • ODBC can connect to other partitions and systems easily
  • PDO’s fetchAll() can retrieve all rows at once, to fetch small recordsets quickly
  • Supports stored procedure output parameters (when needed) better than the other extensions

Example script using PDO_ODBC to query the sample QCUSTCDT table

We included try/catch blocks to demonstrate good error handling.

 

Note about special characters

If the User ID or Password contains a semicolon (;), wrap the value in curly braces:

More about PDO_ODBC

0 replies

Leave a Reply

Want to join the discussion?
Feel free to contribute!

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.