Db2 connection problem with IBM DB2

两盒软妹~` 提交于 2019-12-11 15:06:25

问题


I am trying to connect a db2 database using php. Now, i am gonna write some code similar to this(call a stored procedure):

$proc = 'CALL MyLib.MySP(?, ?, ?)'; 
$stmt = db2_prepare($conn, $proc) or die("db2_prepare failed<br>"); 

// Define input variable values // 
$paramIN1  = ...; 
$paramIN2  = ...; 
$paramOUT3 = ""; 

// Define parameters // 
db2_bind_param($stmt, 1, "paramIN1", DB2_PARAM_IN); 
db2_bind_param($stmt, 2, "paramIN2", DB2_PARAM_IN); 
db2_bind_param($stmt, 3, "paramOUT3", DB2_PARAM_OUT); 

// Display results set // 
if (db2_execute($stmt)) { 
    while ($row = db2_fetch_array($stmt)) { 
        print "  {$row[0]}, {$row[1]}, {$row[5]}<br>"; 
    } 
}

Connection code:

$user = 'user';
$password = 'pass';
$hostname = 'ip';
$db = 'db';
$conn_string = "DRIVER={IBM DB2 ODBC DRIVER};HOSTNAME=$hostname;PROTOCOL=TCPIP;UID=$user;PWD=$password;DATABASE=$db;";

$conn = db2_connect($conn_string, $user, $password);

Connection fails here. Error message returned from db2_conn_errormsg() is:

"[IBM][CLI Driver] SQL1032N No start database manager command was issued. SQLSTATE=57019 SQLCODE=-1032"

This is an AS/400 system. With odbc we can connect and talk to database without a problem.


回答1:


[IBM][CLI Driver] is the DB2 ODBC driver not the iSeries Access ODBC driver. From what I can discern it also requires DB2 Connect to enable a connection to an AS/400 host.

A failure to connect using the iSeries Access ODBC driver results in the following message:

[IBM][iSeries Access ODBC Driver]Communication link failure. comm rc=8015 - CWBSY1006 - User ID is invalid, Password length = 0, Prompt Mode = Never, System IP Address = 127.0.0.1

Check the database driver on your ODBC DSN.




回答2:


You can connect with db2 using:

$dbh = db2_connect('*LOCAL', $user, $password, array("i5_lib"=> $db);

If the DB2 database and the ZendServer are in the same IBM i then '*LOCAL', else the DB2 name.



来源:https://stackoverflow.com/questions/6980927/db2-connection-problem-with-ibm-db2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!