[英]Connect IBM database using PDO
I tried connect IBM database through PDO using below code. 我尝试使用以下代码通过PDO连接IBM数据库。 But, it is not working
但是,它不起作用
try {
$db = new PDO("odbc:DRIVER={IBM DB2 ODBC DRIVER};DATABASE=BLUDB;HOSTNAME=hostname;PORT=50000;PROTOCOL=TCPIP;", "username", "password");
echo "<pre>";
print_r($db);
exit;
} catch (PDOException $e) {
echo $e->getMessage();
}
I got below error for the same 我同样遇到错误
SQLSTATE[IM002] SQLDriverConnect: 0 [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified
I have also added below code in php.ini file 我还在php.ini文件中添加了以下代码
extension=php_pdo.dll
extension=php_pdo_ibm.dll
extension=php_ibm_db2.dll
Could anyone suggest me, how I can connect with IBM database? 谁能建议我,我该如何连接IBM数据库?
The DSN prefix for DB2 databases is ibm:
, not odbc:
. DB2数据库的DSN前缀是
ibm:
而不是odbc:
Try changing that. 尝试更改它。
Here is the example connection string given in the documentation: 这是文档中给出的示例连接字符串:
$db = new PDO("ibm:DRIVER={IBM DB2 ODBC DRIVER};DATABASE=testdb;" .
"HOSTNAME=11.22.33.444;PORT=56789;PROTOCOL=TCPIP;", "testuser", "tespass");
there is different driver name for some computer, this is the list of driver you can try: 某些计算机的驱动程序名称不同,这是您可以尝试使用的驱动程序列表:
and try to use System
instead of HOSTNAME
并尝试使用
System
而不是HOSTNAME
DRIVER={iSeries Access ODBC Driver};DATABASE=BLUDB;System=hostname;PORT=50000;PROTOCOL=TCPIP;
oh, and I'm using DRIVER={IBM i Access ODBC Driver};
哦,我正在使用
DRIVER={IBM i Access ODBC Driver};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.