Installation of DB2 Linux, Unix, Window (LUW) contains server and client tools. That means DB2 LUW can act as server and also as a client.
Every database connection on DB2 registered on catalog. Database has parent node catalog. So catalogues are tree view looks like. Local databases are automatically registered in database catalog.
To connect to remote database server we need to make catalog for the remote connection. After remote catalog has been registered, remote server will appear as local.
To view all node registered use this syntax on IBM DB2 Command window : db2 list node directory
To view registered database catalog use : db2 list db directory
To add new db catalog that connect to remote server use:
DB2 CATALOG TCPIP NODE <remotenode> REMOTE <server-ip.address> SERVER <port>
DB2 CATALOG DATABASE <dbname> AS <dbname.alias> AT NODE <remotenode>
Replace <remotenode> with name of remote node, <server-ip.address> with remote server ip address, <port> with connection port, <dbname> with database name, <dbname.alias> with database alias.
We will see remote server that act as local server. We can administer it and run queries against it through any db2 tools like IBM DB2 Control Center, Command Control and Data Studio.
At my previous post, I explain and give example how to connect and run queries on DB2 using PHP. It looks like the connection using localhost db2 server.
The methop PHP connect to remote database is the same. After remote database cataloged you can use PHP syntax like below:
$remote_dbname = "TestDB";
$userid = "guest";
$pwd = "12345";
$conn = db2_connect($remote_dbname,$userid,$pwd);