我正在使用PHP腳本中的ibm_db2驅動程序在AS/400 V7R2上運行。儘管失敗,db2_connect()仍會返回資源ID
我發現,如果我傳遞一個無效的庫列表db2_connect()
與i5_libl
選項與連接字符串是有效的休息,它仍然會盡管ini_set("display_errors", 1);
所報告的錯誤返回的資源ID。另外,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";
}
?>