0

I having the following error to connect IBM DB2.

Connection failed.[unixODBC][Driver Manager]Data source name not found, and no default driver specified SQLCODE=0

and this is the configuration for db2 in my phpinfo.

IBM DB2, Cloudscape and Apache Derby support:   enabled
Module release :    1.9.4
Module revision :   $Revision: 327944 $
Binary data mode (ibm_db2.binmode) :    DB2_BINARY
DB2 instance name (ibm_db2.instance_name) ; no value

Plz help me to connect the database.

The script is as below.

$database = 'dbT';
$user = 'user';
$password = 'pswd';
$hostname = '10.250.10.11';
$port = 456;


$conn_string = "DRIVER={IBM DB2 ODBC DRIVER};DATABASE=$database;" .
  "HOSTNAME=$hostname;PORT=$port;PROTOCOL=TCPIP;UID=$user;PWD=$password;";
$conn = db2_connect($conn_string, '', '');


print $conn;

if ($conn) {
    echo "Connection succeeded.";
    db2_close($conn);
}
else {
print($conn);
    echo "Connection failed.";
    die(db2_conn_errormsg());
}
1
  • It looks like your script either can't find or doesn't have permission to open the IBM DB2 ODBC driver. Commented Nov 13, 2012 at 12:41

1 Answer 1

1

Data source name not found, and no default driver specified SQLCODE=0

The unixODBC driver manager can not find a DRIVER called [IBM DB2 ODBC DRIVER] in the list of driver within its odbcinst.ini file.

Run :-

odbcinst -j

This will show something like :-

unixODBC 2.3.0
DRIVERS............: /etc/odbcinst.ini
SYSTEM DATA SOURCES: /etc/odbc.ini
FILE DATA SOURCES..: /etc/ODBCDataSources
USER DATA SOURCES..: /home/richard/.odbc.ini
SQLULEN Size.......: 4
SQLLEN Size........: 4
SQLSETPOSIROW Size.: 2

Take a look in the "Drivers" file for your data source. If it's not there you'll need to add one. If it is there check that the library being referenced is in your machines library path.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.