I have a PHP script that calls a function sometimes multiple times in one script run.
The function looks like this:
function insert_values($values) {
$sql = "insert into...";
pg_prepare($connection,"statement_name",$sql);
pg_execute($connection,"statement_name",array($values));
}
Everything is good so far - when it executes once
However, if my script calls this function more than once on that same connection, PHP gives a warning as:
[Tue Dec 01 20:58:31 2015] [error] [client 10.64.241.13] PHP Warning: pg_prepare(): Query failed: ERROR: prepared statement "insert_values" already exists in /var/www/include/classes/classes.php on line 955
Now, if this was just a a simple PHP warning, I might not pay attention to it.
However on the Postgres end, it states Query failed: ERROR
- so of course the query does not run.
Obviously I understand why Postgres would kill somebody creating a NEW prepared statement with the same name on the same connection.
So.... does anybody know if there is a simple way to check if
the prepared statement already exists and if it already exists, then just to take the already-created prepared statement?
Thank you.