PHP PDOException MySql Error Codes and Messages

PDO Exception


PDOException extends RuntimeException {
/* Properties */
public array $errorInfo ;
protected string $code ;
/* Inherited properties */
protected string $message ;
protected int $code ;
final public string Exception::getMessage ( void )
final public mixed Exception::getCode ( void ))
}


http://php.net/manual/en/class.pdoexception.php

errorInfo
Corresponds to PDO::errorInfo() or PDOStatement::errorInfo()

code
SQLSTATE error code. Use Exception::getCode() to access it.

PDO::errorInfo — Fetch extended error information associated with the last operation on the database handle

Description ¶

public array PDO::errorInfo ( void )
Return Values ¶

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

Element	Information
0	SQLSTATE error code (a five characters alphanumeric identifier defined in the ANSI SQL standard).
1	Driver-specific error code.
2	Driver-specific error message.
Note:
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.


PDO::errorCode

(PHP 5 >= 5.1.0, PECL pdo >= 0.1.0)
PDO::errorCode — Fetch the SQLSTATE associated with the last operation on the database handle

Description ¶

public mixed PDO::errorCode ( void )
Return Values ¶

Returns an SQLSTATE, a five characters alphanumeric identifier defined in the ANSI SQL-92 standard. Briefly, an SQLSTATE consists of a two characters class value followed by a three characters subclass value. A class value of 01 indicates a warning and is accompanied by a return code of SQL_SUCCESS_WITH_INFO. Class values other than '01', except for the class 'IM', indicate an error. The class 'IM' is specific to warnings and errors that derive from the implementation of PDO (or perhaps ODBC, if you're using the ODBC driver) itself. The subclass value '000' in any class indicates that there is no subclass for that SQLSTATE.

PDO::errorCode() only retrieves error codes 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::errorCode() will not reflect that error. You must call PDOStatement::errorCode() to return the error code for an operation performed on a particular statement handle.

Returns NULL if no operation has been run on the database handle.

Examples ¶

Example #1 Retrieving an SQLSTATE code

<?php
/* Provoke an error -- the BONES table does not exist */
$dbh->exec("INSERT INTO bones(skull) VALUES ('lucy')");

echo "\nPDO::errorCode(): ", $dbh->errorCode();
?>
The above example will output:

PDO::errorCode(): 42S02

http://docstore.mik.ua/orelly/java-ent/jenut/ch08_06.htm

SQL-92 SQLSTATE Return Codes

Class

Class Definition

Subclass

Subclass Definition

00

Successful completion

000

None

01

Warning

000

None

001

Cursor operation conflict

002

Disconnect error

003

Null value eliminated in set function

004

String data, right truncation

005

Insufficient item descriptor areas

006

Privilege not revoked

007

Privilege not granted

008

Implicit zero-bit padding

009

Search expression too long for information schema

00A

Query expression too long for information schema

02

No data

000

None

07

Dynamic SQL error

000

None

001

Using clause doesn't match dynamic parameters

002

Using clause doesn't match target specifications

003

Cursor specification can't be executed

004

Using clause required for dynamic parameters

005

Prepared statement not a cursor specification

006

Restricted data type attribute violation

007

Using clause required for result fields

008

Invalid descriptor count

009

Invalid descriptor index

08

Connection Exception

000

None

001

SQL-client unable to establish SQL-connection

002

Connection name in use

003

Connection doesn't exist

004

SQL-server rejected establishment of SQL-connection

006

Connection failure

007

Transaction resolution unknown

0A

Feature not supported

000

None

001

Multiple server transactions

21

Cardinality violation

000

None

22

Data exception

000

None

001

String data, right truncation

002

Null value, no indicator

003

Numeric value out of range

005

Error in assignment

007

Invalid date-time format

008

Date-time field overflow

009

Invalid time zone displacement value

011

Substring error

012

Division by zero

015

Internal field overflow

018

Invalid character value for cast

019

Invalid escape character

021

Character not in repertoire

022

Indicator overflow

023

Invalid parameter value

024

Unterminated C string

025

Invalid escape sequence

026

String data, length mismatch

027

Trim error

23

Integrity constraint violation

000

None

24

Invalid cursor state

000

None

25

Invalid transaction state

000

None

26

Invalid SQL statement name

000

None

27

Triggered data change violation

000

None

28

Invalid authorization specification

000

None

2A

Syntax error or access rule violation in direct SQL statement

000

None

2B

Dependent privilege descriptors still exist

000

None

2C

Invalid character set name

000

None

2D

Invalid transaction termination

000

None

2E

Invalid connection name

000

None

33

Invalid SQL descriptor name

000

None

34

Invalid cursor name

000

None

35

Invalid condition number

000

None

37

Syntax error or access rule violation in dynamic SQL statement

000

None

3C

Ambiguous cursor name

000

None

3F

Invalid schema name

000

None

40

Transaction rollback

000

None

001

Serialization failure

002

Integrity constraint violation

003

Statement completion unknown

42

Syntax error or access rule violation

000

None

44

With check option violation

000

None



Server Error Codes and Messages

https://dev.mysql.com/doc/refman/5.7/en/error-messages-server.html




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章