2015-09-24 34 views
0

我正在使用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"; 
} 
?> 

回答

0

我結束了打開與Zend一張票,事實證明這是預期的行爲。

正如我們所知,i5_libl選項根據http://php.net/manual/en/function.db2-connect.php調用qsys2/qcmdexc('cmd',cmdlen)。但邏輯上必須建立連接以便知道哪個QSQSRVR作業更改庫列表。不是在發生故障時關閉連接,而只是發出警告,db_conn_error()db2_connerrormsg()報告一切正常。

好在這個註冊爲一個語句錯誤,這可以通過以下進行檢測:

if (db2_stmt_error()) { 
    echo "error ID: " . (db2_stmt_error()); 
    echo "<br>error message: " . (db2_stmt_errormsg()); 
} 

我建議Zend公司關閉連接或強制連接錯誤或東西。我想不出任何我想用庫列表連接到數據庫的實例,而不是在沒有任何警告或明顯通知的情況下指定的。如果開發和生產數據相互交織,這可能會導致災難。