我正在使用 PHP 脚本中的 ibm_db2 驱动程序在 AS/400 V7R2 上运行。
我注意到如果我将一个无效的库列表传递给db2_connect()
该i5_libl
选项,并且连接字符串的其余部分是有效的,它仍然会返回一个资源 ID,尽管ini_set("display_errors", 1);
. 此外,db2_conn_error()
并且db2_conn_errormsg()
不包含任何内容。另一方面,当我确实提供了一个有效的库列表时,我的IF
语句评估方式完全相同,唯一的区别是错误不会输出到屏幕ini_set("display_errors", 1);
我意识到,不是由于无效的库列表而失败,而是使用提供的数据库用户名的默认库列表建立连接。这对我来说可能很可怕,因为如果由于某种原因我的库列表无效,它将默认为错误的列表(主要关注的是开发和生产环境的混合)。
其他人可以重现这种行为吗?我不知道这是否只是我的系统并且我需要 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";
}
?>