DB2

From RadPHP XE2 Documentation
Jump to: navigation, search

Contents

Initial Setup

To get PHP and DB2 working together, follow these steps:

  1. Get DB2 Lite client from ibm.com/support/docview.wss?rs=71&uid=swg27013326.
  2. Extract the archive with the client, and copy all .dll files into your Windows\System32 directory.
  3. Download DB2 PHP Extension from pecl.php.net/get/ibm_db2.
  4. Extract php_ibm_db2.dll to the php\ext directory inside RadPHP installation folder.
  5. 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

Personal tools