Opux Opux - 2 years ago 111
PHP Question

PostgreSQL: getting error messages from `pg_convert()`

I'm trying to diagnose a problem only found on a production system and I'm trying to improve the error reporting for errors thrown by

, but not sure where to go. I tried changing the code in the dev environment to:

$converted_values = pg_convert($cnx, $table, $values);
if ($converted_values === FALSE)
throw new Exception("Failed to insert record: '".pg_last_error($cnx)."' using values: ".var_export($values, true));

returned nothing.

Note: I tested the above by trying to insert a null value into a
column. In addition to getting no joy from
the log had some "PHP Notice"s in it. The production log didn't have any such notices. Just the empty return value from

I'm running PostgreSQL 9.4.6 on Debian 8.3 and PHP 5.6.22.

Answer Source

From what I can tell, trying to get anything done w/pg_convert() is a bust. It's not very reliable in dealing w/different data, and it's inconsistent about putting double quotes around column names. If you're using pg_convert() you'll likely want to convert to prepared statements. What they do is very different, so you might have to make fundamental changes to your code base, but we made the change and it seems to be working for us.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download