From: "Gary ." on
I asked something similar to this on the ph-db ml yesterday, but that
list seems to be almost dead.

The situation I have is that I am trying to get the postgres error
code (as opposed to some error message - see my other posts to this
list over the last day or so for the background to that). I found I
could use pg_result_error_field to do this, but that requires me using
pg_get_result (and, basically, the rest of the async part of the
interface). That's okay. As long as I can get the error code I'm happy
enough with that in principle.

The problem is that I have my asynchronous inserts wrapped in a transaction:
BEGIN
for (...)
{
pg_send_execute(...);
}
COMMIT

So, where should my pg_get_result and other error checking go? I've
put it immediately after the while loop, and it works okay in a
phpunit-test that forces a UNIQUEness constraint to fire - the code
picks up the expected 23505 error code, and I can get that in the
client code and translate it to a nice user message. However, running
through the normal interface, provoking the same error, I instead get
25P02 ("in_failed_sql_transaction"). Why, and how can I make sure I
get the original error?

TIA.