|
oci_error (PHP 5) oci_error -- 返回上一個錯誤 說明array oci_error ( [resource source] )
對於大多數錯誤,參數是最適合的資源識別碼。對於
oci_connect(),oci_new_connect()
或 oci_pconnect()
的連線錯誤,不要傳遞參數。若果沒有發現錯誤,oci_error()
返回 FALSE。oci_error()
以一個關聯陣列返回錯誤。在此陣列中,code
是 oracle 錯誤代碼而 message 是 oracle 的錯誤字串。
自 PHP 4.3 起:
offset 和 sqltext
也內含在返回的陣列中,用來指出錯誤發生的位置以及造成錯誤的原始的 SQL 文字。
例子 1. 連線錯誤後顯示 Oracle 錯誤訊息
$conn = @oci_connect("scott", "tiger", "mydb"); if (!$conn) { $e = oci_error(); // For oci_connect errors pass no handle echo htmlentities($e['message']); }
|
|
例子 2. 語法解析錯誤後顯示 Oracle 錯誤訊息
$stmt = @oci_parse($conn, "select ' from dual"); // note mismatched quote if (!$stmt) { $e = oci_error($conn); // For oci_parse errors pass the connection handle echo htmlentities($e['message']); }
|
|
例子 3. 執行錯誤後顯示 Oracle 錯誤訊息和出錯的語句
$r = oci_execute($stmt); if (!$r) { $e = oci_error($stmt); // For oci_execute errors pass the statementhandle echo htmlentities($e['message']); echo "<pre>"; echo htmlentities($e['sqltext']); printf("\n%".($e['offset']+1)."s", "^"); echo "</pre>"; }
|
|
注:
在 PHP 5.0.0 之前的版本必須使用 ocierror()
替代本函數。該函數名仍然可用,為向下相容作為
oci_error() 的別名。不過其已被廢棄,不推薦使用。
| |