【发布时间】:2015-09-24 13:35:28
【问题描述】:
我正在使用 PHP 脚本中的 ibm_db2 驱动程序在 AS/400 V7R2 上运行。
我注意到,如果我使用i5_libl 选项将无效的库列表传递给db2_connect(),并且连接字符串的其余部分有效,尽管ini_set("display_errors", 1); 报告了错误,它仍将返回资源ID。此外,db2_conn_error() 和 db2_conn_errormsg() 不包含任何内容。另一方面,当我提供一个有效的库列表时,我的IF 语句的评估方式完全相同,唯一的区别是ini_set("display_errors", 1); 没有将错误输出到屏幕
我意识到,不是因为无效的库列表而失败,而是使用提供的 DB 用户名的默认库列表建立连接。这对我来说可能很可怕,因为如果由于某种原因我的库列表无效,它将默认为错误的列表(主要关注的是开发和生产环境的混合)。
其他人可以重现这种行为吗?我不知道这是否只是我的系统并且我需要 PTF,或者这是否是典型的。您如何验证已使用预期选项建立 DB2 连接?
要重现的代码(相应地替换系统名称、用户名和密码):
<?php
ini_set("display_errors", 1);
$systemName = 'yourSystemName';
$userID = 'yourUserID';
$password = 'yourPassword';
$options['i5_libl'] = implode('Z', array(
'INVALID',
'LIB',
'LIST',
'IMPLODED',
'WITH',
'THE',
'LETTER',
'Z'
));
$options['i5_naming'] = DB2_I5_NAMING_ON;
$conn = db2_connect($systemName,$userID,$password,$options);
//The error output to the screen at this point from `ini_set("display_errors", 1);` is:
//Warning: db2_connect(): Statement Execute Failed in /PATH/TO/FILE/test.php on line 58
echo "<br />|".db2_conn_error()." ||| ".db2_conn_errormsg()."|<br />"; //This displays as "| ||| |"
print_r($conn); //This prints out a resource ID
echo "<br />";
if(isset($conn) && $conn === true){
//Expected to not pass since either false or a resource ID is supposed to be returned.
//Evaluated to false.
echo "Boolean true<br />";
}
if(isset($conn) && $conn == true){
//Despite the connection failing according to `ini_set("display_errors", 1)` and a resource ID being reportedly returned
//this evaluates to true and "Non-Boolean true 2" echos out to the screen.
echo "Non-Boolean true 2<br />";
}
if(isset($conn) && $conn == "true"){
//Evaluates to false. db2_connect() returns a resource ID on success, so I did not expect this to evaluate to true.
echo "String true";
}
if(isset($conn) && $conn === false){
//Expected for this to evaluate to true since an error was logged by ini_set("display_errors", 1)
//This did not evaluate to true.
echo "Boolean false<br />";
}
if(isset($conn) && $conn == false){
//Just checking to see if a non-Boolean false was returned. Evaluates to false.
echo "Non-Boolean false 2<br />";
}
if(isset($conn) && $conn == "false"){
//Just checking to see if the string "false" was returned. Evaluates to false.
echo "String false";
}
?>
【问题讨论】:
标签: php db2-400 db2-connect ibm-db2