Forum Moderators: coopster

Message Too Old, No Replies

Connecting my Apache/PHP server to a DB2 server on a different machine

DB2 and PHP server on different machines

         

Verity9802

11:46 am on Jul 15, 2004 (gmt 0)

10+ Year Member



Hi all,
I'm not sure if this is the right forum for this question but I shall give it a shot anyway! I want my Apache/PHP server to connect to an IBM DB2 server on a different machine but I'm not too sure how to go about doing this. Both the machines are Window 2000. I can't use odbc_connect() since it doesn't take in a server parameter. I'm sure there's a way around this but it's got me stumped so far. Any sort of help would be greatly appreciated. Cheers.

lorax

2:18 pm on Jul 15, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



If you mean to get data from the DB2 box then you'll need to use some sort of RPCs (remote procedure calls). These are simple routines that will allow you to query the database when called and return the data they were programmed to get.

It goes something like this. You'd write the PHP script for your webserver and it would query the DB2 box using SOAP, XML-RPC, or WDDX. The DB2 box would have a set of RPCs available to you that would perform the specific tasks and return the data.

Verity9802

3:13 pm on Jul 15, 2004 (gmt 0)

10+ Year Member



What I mean is that I want to connect to a DB2 server on a different machine from the machine that hosts my Apache/PHP server. For example, I can do this with MySQL if I use the function "mysql_connect ( [string server [, string username [, string password [, bool new_link [, int client_flags]]]]])", whereby I can specify the machine I want to connect to in the "server" parameter. This would enable me to access the database on that machine and it would be like I'm on a local machine. However, I can't do this with "odbc_connect ( string dsn, string user, string password [, int cursor_type])" as it doesn't ask for a server parameter. I'm sure there's a way around this but I haven't found the solution to it.

coopster

3:59 pm on Jul 15, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



You specify it in your dsn. There are a number of ways to do this, such as creating a data source on each accessing PC. However, that's not a very realistic solution for us developers so I prefer using a "DSN-less" connect string on the connect by scripting it into a variable, $dsn.
$dsn = 'DRIVER={driver_name_here}; other_required_variables_here;'; 
$db_link = odbc_connect($dsn, $user, $pwd, SQL_CUR_USE_ODBC)