php连接DB2
在php.ini中添加对DB2的支持
////////////////////////////////////////////////////
;;;;;;;;;;;;;;;;;;;;;;; Dynamic Extensions ;
;;;;;;;;;;;;;;;;;;;;;;
extension=php_ibm_db2.dll
///////////////////////////////////////////////////
<?php
$database = 'dbname';
$user = 'dbuser';
$password = '123456';
$hostname = '59.0.0.0';
$port = 50000;
$conn_string = "DRIVER={IBM DB2 ODBC DRIVER};DATABASE=$database;" .
"HOSTNAME=$hostname;PORT=$port;PROTOCOL=TCPIP;UID=$user;PWD=$password;";
$conn = db2_connect($conn_string, '', '');
if ($conn) {
echo "Connection succeeded!";
$sql_str='select * from t_table where 1=1 fetch first 1 rows only';
$result=db2_exec($conn,$sql_str);
while ($arr = db2_fetch_array($result)) {
print_r($arr);
}
}
else {
echo "Connection failed.";
}
db2_close($conn);
?>