phppdoerror-handling

PDO errorInfo, how to get the full List of Error codes?


I'm working on a big database were i created links between primary and foreign keys. I'm using "Apache/2.4.34 (Win32) OpenSSL/1.1.0i PHP/7.2.10" and my codes are built with the PDO methods.

While i'm testing the delete functionality, i'm getting this message from the errorInfo:

    Array ( 
[0] => 23000 
[1] => 1451 
[2] => Cannot delete or update a parent row: a foreign key constraint fails (`#DBNAME#`.`#TABLE1-NAME#`, CONSTRAINT `#CONSTRAINT-NAME#` FOREIGN KEY (`user_id`) REFERENCES `#TABLE2-NAME#` (`id`)) ) Cannot delete or update a parent row: a foreign key constraint fails 

I know that error is caused by trying to delete a records with a primary key related to other foreign keys. What i was wondering about is the error code number, can i assume always when i receive this number 1451 that the error is between primary and foreign key, or could it be linked to some other errors as well?

And i tried searching for a full list of errorInfo codes with its error message with no success. Can someone let me know if this list existe somewhere on the internet. Thanks


Solution

  • A List of MySQL Errors with its Messages can be found here: Error List
    Following this list your error code is only for this specific message.

    Also, a list of MariaDB Errors