Jump to content

Recommended Posts

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?

 
Link to comment
https://forums.phpfreaks.com/topic/304926-in-pdoexception/
Share on other sites

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?

Link to comment
https://forums.phpfreaks.com/topic/304926-in-pdoexception/#findComment-1551048
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/304926-in-pdoexception/#findComment-1551051
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.