DB2
From RadPHP XE2 Documentation
Contents |
Initial Setup
To get PHP and DB2 working together, follow these steps:
- Get DB2 Lite client from ibm.com/support/docview.wss?rs=71&uid=swg27013326.
- Extract the archive with the client, and copy all .dll files into your Windows\System32 directory.
- Download DB2 PHP Extension from pecl.php.net/get/ibm_db2.
- Extract php_ibm_db2.dll to the php\ext directory inside RadPHP installation folder.
- Add the following line to RadPHP php.ini.template file:
- extension=php_ibm_db2.dll
Usage
Database Setup
To use a Database component with DB2, set it up so it uses DB2 driver:
- DriverName: db2.
Do not forget to fill also the rest of the basic information.
Work From Code
To access a DB2 database from PHP code, you can do like this:
// Set Connection Data $database = 'database'; // Name of the database. $user = 'user'; // Username to access the database. $password = 'password'; // Password for the user. $hostname = 'hostname'; // Address of the machine where the DBMS is running. $port = 'port' // Port number through which DBMS can be accessed on given hostname. // Establish Connection $connection_data = "DRIVER={IBM DB2 ODBC DRIVER};"; $connection_data .= "DATABASE=$database;"; $connection_data .= "HOSTNAME=$hostname;"; $connection_data .= "PORT=$port;"; $connection_data .= "PROTOCOL=TCPIP;"; $connection_data .= "UID=$user;"; $connection_data .= "PWD=$password;"; $connection = db2_connect($connection_data, '', ''); // Connection Test if (!$connection) echo 'DB2 Database could not be reached'; else echo 'Succesfully connected to DB2 database';
See Also
- php.net/manual/en/ref.ibm-db2.php (DB2 PHP Documentation)
- ibm.com/developerworks/data/library/techarticle/dm-0502scott/ (IBM Documentation on PHP and DB2)
- sqlrelay.sourceforge.net/sqlrelay/gettingstarted/db2.html (Introduction to DB2)