百科狗-知识改变命运!
--

PDO::errorInfo() - PDO类

乐乐12个月前 (11-21)阅读数 18#技术干货
文章标签句柄

PDO::errorInfo()

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

Fetch extended error information associated with the last operation on the database handle

说明

publicPDO::errorInfo(void): array

返回值

PDO::errorInfo() returns an array of error information about the last operation performed by this database handle. The array consists of at least the following fields:

ElementInformation
0SQLSTATE error code(a five characters alphanumeric identifier defined in the ANSI SQL standard).
1Driver-specific error code.
2Driver-specific error message.
Note:

PDO::errorInfo() - PDO类

If the SQLSTATE error code is not set or there is no driver-specific error, the elements following element 0 will be set to NULL.

PDO::errorInfo() only retrieves error information for operations performed directly on the database handle. If you create a PDOStatement object through PDO::prepare() or PDO::query() and invoke an error on the statement handle,PDO::errorInfo() will not reflect the error from the statement handle. You must call PDOStatement::errorInfo() to return the error information for an operation performed on a particular statement handle.

范例

Displaying errorInfo()fields for a PDO_ODBC connection to a DB2 database

以上例程会输出:

PDO::errorInfo():
Array
(
    [0] => HY000
    [1] => 1
    [2] => near "bogus": syntax error
)

参见

  • PDO::errorCode() 获取跟数据库句柄上一次操作相关的 SQLSTATE
  • PDOStatement::errorCode() 获取跟上一次语句句柄操作相关的 SQLSTATE
  • PDOStatement::errorInfo() 获取跟上一次语句句柄操作相关的扩展错误信息
Please note : that this example won't work if PDO::ATTR_EMULATE_PREPARES is true. 
You should set it to false 
here are the error codes for sqlite, straight from their site:
The error codes for SQLite version 3 are unchanged from version 2. They are as follows: 
#define SQLITE_OK      0  /* Successful result */
#define SQLITE_ERROR    1  /* SQL error or missing database */
#define SQLITE_INTERNAL   2  /* An internal logic error in SQLite */
#define SQLITE_PERM     3  /* Access permission denied */
#define SQLITE_ABORT    4  /* Callback routine requested an abort */
#define SQLITE_BUSY     5  /* The database file is locked */
#define SQLITE_LOCKED    6  /* A table in the database is locked */
#define SQLITE_NOMEM    7  /* A malloc() failed */
#define SQLITE_READONLY   8  /* Attempt to write a readonly database */
#define SQLITE_INTERRUPT  9  /* Operation terminated by sqlite_interrupt() */
#define SQLITE_IOERR    10  /* Some kind of disk I/O error occurred */
#define SQLITE_CORRUPT   11  /* The database disk image is malformed */
#define SQLITE_NOTFOUND  12  /* (Internal Only) Table or record not found */
#define SQLITE_FULL    13  /* Insertion failed because database is full */
#define SQLITE_CANTOPEN  14  /* Unable to open the database file */
#define SQLITE_PROTOCOL  15  /* Database lock protocol error */
#define SQLITE_EMPTY    16  /* (Internal Only) Database table is empty */
#define SQLITE_SCHEMA   17  /* The database schema changed */
#define SQLITE_TOOBIG   18  /* Too much data for one row of a table */
#define SQLITE_CONSTRAINT 19  /* Abort due to contraint violation */
#define SQLITE_MISMATCH  20  /* Data type mismatch */
#define SQLITE_MISUSE   21  /* Library used incorrectly */
#define SQLITE_NOLFS    22  /* Uses OS features not supported on host */
#define SQLITE_AUTH    23  /* Authorization denied */
#define SQLITE_ROW     100 /* sqlite_step() has another row ready */
#define SQLITE_DONE    101 /* sqlite_step() has finished executing */
Some PDO drivers return a larger array. For example, the SQL Server driver returns 5 values.
For example:

Result:
Array
(
  [0] => 00000
  [1] => 0
  [2] => (null) [0] (severity 0) []
  [3] => 0
  [4] => 0
)
I don't know why mazen at mindcraftinc dot com is getting that amount of negative votes: in my case, I've constated that with odbc_driver and an Access database, this method is returning ONE extra field appart from what is stated in this manual.
More precisely, if using the PDO odbc_pdo driver with an Access database, in a fourth array element I'm getting the ODBC Status Return Code.

鹏仔微信 15129739599 鹏仔QQ344225443 鹏仔前端 pjxi.com 共享博客 sharedbk.com

免责声明:我们致力于保护作者版权,注重分享,当前被刊用文章因无法核实真实出处,未能及时与作者取得联系,或有版权异议的,请联系管理员,我们会立即处理! 部分文章是来自自研大数据AI进行生成,内容摘自(百度百科,百度知道,头条百科,中国民法典,刑法,牛津词典,新华词典,汉语词典,国家院校,科普平台)等数据,内容仅供学习参考,不准确地方联系删除处理!邮箱:344225443@qq.com)

图片声明:本站部分配图来自网络。本站只作为美观性配图使用,无任何非法侵犯第三方意图,一切解释权归图片著作权方,本站不承担任何责任。如有恶意碰瓷者,必当奉陪到底严惩不贷!

内容声明:本文中引用的各种信息及资料(包括但不限于文字、数据、图表及超链接等)均来源于该信息及资料的相关主体(包括但不限于公司、媒体、协会等机构)的官方网站或公开发表的信息。部分内容参考包括:(百度百科,百度知道,头条百科,中国民法典,刑法,牛津词典,新华词典,汉语词典,国家院校,科普平台)等数据,内容仅供参考使用,不准确地方联系删除处理!本站为非盈利性质站点,本着为中国教育事业出一份力,发布内容不收取任何费用也不接任何广告!)