Which class they are telling about in the returned value of PDO::errorCode (void) in php?

user9058188

As we know that PDO::errorCode ( void ) method returns the SQLSTATE where the returned value is the alphanumeric identifier of 5 characters, where the first two characters are the value of Class and the rest of the three characters are the value of the SubClass. My question is that about which Class & SubClass they are telling ? Either it is PDO class or anything else ?

Reference Link: PDO->errorCode(void)

Please can any one tell ?

Thanks !!!

Barmar

This class and subclass has nothing to do with PDO or PHP classes, or object orientation at all. It just refers to the way that errors are categorized in SQL. As it says in the documentation, the error code is

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
...
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

So except for class IM, these codes come from the database. They're the same codes you'll see if you query the database using command line tools and get an error, e.g.

mysql> select a from foo bar baz;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'baz' at line 1

42000 is the error code, its class is 42 and subclass is 000. If you made this same query using PDO, $pdo->errorCode() would return "42000", and $pdo->errorInfo would return an array like:

[ "42000", 
  1004, 
  "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'baz' at line 1"   
]

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related