I am using PDO with the OCI driver. A particular INSERT query of mine is causing a trigger error:
ERROR at line 1:
ORA-01403: no data found
ORA-06512: at "FOO.BAR", line 5
ORA-04088: error during execution of trigger 'FOO.BAR'
However, an exception is not being thrown when this happens. I am using ERRMODE_EXCEPTION, and exceptions are thrown fine for standard query syntax errors and such, but not for any error originating from a trigger.
The call to $st->execute() does not return FALSE in this case either. Also, $st->errorInfo() and $st->errorCode() are both unhelpful, as well:
array(3) {
[0]=>
string(5) "00000"
[1]=>
NULL
[2]=>
NULL
}
string(5) "00000"
How can I get PDO to throw an exception when a trigger error happens? Or, if that’s impossible, how can I programmatically detect when this happens by other means? The only way I even know that an error happened in the first place (aside from the database not being updated) is that $st->rowCount() is reporting 0. But this is not a unique or reliable way by itself of determining whether an error occurred…
It’s impossible. Triggers (and events) are run on the DB based on DB actions and are not directly tied your query–at least as seen on the PHP side. Your PDO query is succeeding and that’s all your statement will ever know, the fact that a trigger was set up to do something based on the results of whatever your statement did to some table is irrelevant.
The options you have are: