oci_error

(PHP 5, PHP 7, PHP 8, PECL OCI8 >= 1.1.0)

oci_error返回上一個(gè)錯(cuò)誤

說明

oci_error(resource $source = ?): array

對(duì)于大多數(shù)錯(cuò)誤,參數(shù)是最適合的資源句柄。對(duì)于 oci_connect(),oci_new_connect()oci_pconnect() 的連接錯(cuò)誤,不要傳遞參數(shù)。如果沒有發(fā)現(xiàn)錯(cuò)誤,oci_error() 返回 falseoci_error() 以一個(gè)關(guān)聯(lián)數(shù)組返回錯(cuò)誤。在此數(shù)組中,code 是 oracle 錯(cuò)誤代碼而 message 是 oracle 的錯(cuò)誤字符串。

注意: 自 PHP 4.3 起

offsetsqltext 也包括在返回的數(shù)組中,用來指出錯(cuò)誤發(fā)生的位置以及造成錯(cuò)誤的原始的 SQL 文本。

示例 #1 連接錯(cuò)誤后顯示 Oracle 錯(cuò)誤信息

$conn = @oci_connect("scott", "tiger", "mydb");
if (!$conn) {
  $e = oci_error();   // For oci_connect errors pass no handle
  echo htmlentities($e['message']);
}

示例 #2 語法解析錯(cuò)誤后顯示 Oracle 錯(cuò)誤信息

$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 執(zhí)行錯(cuò)誤后顯示 Oracle 錯(cuò)誤信息和出錯(cuò)的語句

$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() 替代本函數(shù)。該函數(shù)名仍然可用,為向下兼容作為 oci_error() 的別名。不過其已被廢棄,不推薦使用。