PDOStatement::errorCode

(PHP 5 >= 5.1.0, PHP 7, PHP 8, PECL pdo >= 0.1.0)

PDOStatement::errorCode 獲取跟上一次語句句柄操作相關(guān)的 SQLSTATE

說明

PDOStatement::errorCode(): string

返回值

PDO::errorCode() 相同,只是 PDOStatement::errorCode() 只取回 PDOStatement 對象執(zhí)行操作中的錯誤碼。

范例

示例 #1 取回一個 SQLSTATE 碼

<?php
/* 引發(fā)一個錯誤 --  BONES 數(shù)據(jù)表不存在 */
$err $dbh->prepare('SELECT skull FROM bones');
$err->execute();

echo 
"\nPDOStatement::errorCode(): ";
print 
$err->errorCode();
?>

以上例程會輸出:

PDOStatement::errorCode(): 42S02

參見

  • PDO::errorCode() - 獲取跟數(shù)據(jù)庫句柄上一次操作相關(guān)的 SQLSTATE
  • PDO::errorInfo() - Fetch extended error information associated with the last operation on the database handle
  • PDOStatement::errorInfo() - 獲取跟上一次語句句柄操作相關(guān)的擴展錯誤信息