DB2 Interface with PHP - IBM DB2

There are three main extensions of PHP that you can use to develop applications with DB2:

  • ibm_db2
  • Unified ODBC

IBM recommends using ibm_db2 or PDO _ODBC to get best results out of DB2 database.

ibm_db2 extension of PHP provides an interface to connect from PHP to IBM DB2 database. ibm_db2 provides a mechanism to connect to both cataloged and non-cataloged databases. This extension provides mechanisms for application developers to issue SQL queries, work with large objects, call stored procedures, use persistent connections, and use prepared SQL statements. It also works on PHP releases below Version 5. Unlike PDO_ODBC, ibm_db2 is based on traditional procedural programming and performs better compared to Unified ODBC functions. ibm_db2 provides built-in functions for getting details about the DB2 database server and client by querying system catalog tables, which provide lots of information about the DB2 database management system. The latest ibm_db2 extension for PHP has been enhanced to support the new XML data type in DB2 V9.

PDO (PHP Data Objects) is an object-oriented, standards-based data access method in PHP, where you can use the same methodology to query the database and fetch data from the supported databases. PDO_ODBC extension is the implementation of the PDO specification. When compiled with DB2 libraries, you can use it to access DB2, Cloudscape™, and Apache Derby databases. This extension provides a mechanism to connect to both local cataloged and non-local (remote) cataloged databases. For a local cataloged database, PDO_ODBC obtains the database server details from the client machine. For a non-local cataloged database, the full details of the remote database are specified in the connection URL. PDO_ODBC also provides access to advanced features of DB2, such as persistent connections, prepared SQL statements, large objects, and stored procedures. It provides better performance compared to Unified ODBC functions.

Unified ODBC
Unified ODBC was the only method for PHP to talk with DB2, Cloudscape, and Apache Derby databases before ibm_db2 or PDO_ODBC was released. Like ibm_db2 and PDO_ODBC, this extension also interacts with DB2 using native CLI calls. It uses the same PHP methods to interact with different databases even if the underlying mechanism is different. But you cannot use this API to call a stored procedure in DB2. Unified ODBC does not use the Object-Oriented methodology. The source code for all the extensions is available for free download in the PECL

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

IBM DB2 Topics