NotionCommotion Posted September 9, 2017 Share Posted September 9, 2017 A MySQL (actually MariaDB) table has a trigger which can throw the following: SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = 'Object ID must be between 0 and 4,194,302'; When run from the SQL shell with out of range data, it responds with: ERROR 1644 (45000): Object ID must be between 0 and 4,194,302 When executed with a PDO prepared statement, the PDOException::message is: "SQLSTATE[45000]: <<Unknown error>>: 1644 Object ID must be between 0 and 4,194,302" How should one replace <<Unknown error>> with some other content? Quote Link to comment https://forums.phpfreaks.com/topic/304926-in-pdoexception/ Share on other sites More sharing options...
requinix Posted September 9, 2017 Share Posted September 9, 2017 You can't. That comes from an internal error lookup table within PHP. https://github.com/php/php-src/blob/master/ext/pdo/pdo_sqlstate.c Take a look if there's an appropriate SQLSTATE in there you can reuse. Quote Link to comment https://forums.phpfreaks.com/topic/304926-in-pdoexception/#findComment-1551047 Share on other sites More sharing options...
NotionCommotion Posted September 9, 2017 Author Share Posted September 9, 2017 You can't. That comes from an internal error lookup table within PHP. https://github.com/php/php-src/blob/master/ext/pdo/pdo_sqlstate.c Take a look if there's an appropriate SQLSTATE in there you can reuse. Thanks. I went with { "22023", "Invalid parameter value" }. I was also considering checking the code in my error handler and doing something custom. Maybe a better approach? I expected to see code 45000 in https://github.com/php/php-src/blob/master/ext/pdo/pdo_sqlstate.c, but it wasn't listed. Does PHP recognize this code value? Quote Link to comment https://forums.phpfreaks.com/topic/304926-in-pdoexception/#findComment-1551048 Share on other sites More sharing options...
requinix Posted September 9, 2017 Share Posted September 9, 2017 45000 is a generic userland error so adding a message wouldn't be any more helpful than the code itself, and seems to be used more in MySQL than other databases. I think it would be alright if you set MYSQL_ERRNO >= 3000 for a custom error number. This is actually the sort of reason why I don't like putting logic in the database... Quote Link to comment https://forums.phpfreaks.com/topic/304926-in-pdoexception/#findComment-1551051 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.