Forum Moderators: coopster

Message Too Old, No Replies

Making a DSN-less connection using ODBC to DB2.

DSN-less connection to DB2

         

Verity9802

2:25 pm on Jul 16, 2004 (gmt 0)

10+ Year Member



Hi all,

I need to make a DSN-less connection to DB2 using ODBC and I was wondering if the code below is right? Although it looks fine to me, I'm getting the following error "Error [IBM][CLI Driver] SQL1013N The database alias name or database name "" could not be found. SQLSTATE=42705 : 08001".

<?php

$connection_string = 'DRIVER={IBM DB2 ODBC DRIVER};SERVER=<servername>;DATABASE=<databasename>';

$user = 'username';
$pass = 'password';

$connection = odbc_connect( $connection_string, $user, $pass );

?>

Have I got the various fields for $connection_string right? Any sort of help would be appreciated. Cheers.

coopster

9:18 pm on Jul 17, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I've done ODBC calls to DB2 on an IBM AS/400 many times using similar syntax. I'm not sure which keywords are required when using UDB DB2 (Windows, *nix, OS2 platforms), but I would like to think it would be similar. Since there is only one database on a 400, you don't really connect to any particular "database", but a COLLECTION. Something as simple as this
$dsn = 'DRIVER={iSeries Access ODBC Driver};SYSTEM=MYSYSTEM;';
would work.

Have you tried ibm.com/db2 to find the API's and more particulary the ODBC connection string syntax for your particular platform? One thing that looks funny to me is the less than and greater than symbols in your connection parms.

Verity9802

9:15 am on Jul 19, 2004 (gmt 0)

10+ Year Member



I finally found a site which shows the correct syntax for making ODBC calls to an IBM DB2 database and it's at [connectionstrings.com...] Hope this is helpful to anyone who isn't sure of the correct syntax for making ODBC calls to any sort of database. BTW, the syntax for making an ODBC call to a DB2 database is "driver={IBM DB2 ODBC DRIVER};Database=myDbName;hostname=myServerName;port=myPortNum;protocol=TCPIP; uid=myUserName; pwd=myPwd". Cheers.

coopster

11:54 am on Jul 19, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



The "Reference" area of this online publication [publib.boulder.ibm.com] from IBM will also give you plenty to use regarding CLI/ODBC API's and connections for DB2 Universal Database.