PDO:PGSQL problem with double prepared statements. (solution included)

php.internals

Thies C . Arntzen

20 years ago
hi, i had a slight problem with Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE [42P05]: Duplicate prepared statement: 7 ERROR: prepared statement "pdo_pgsql_stmt_086eebf4" already exists' in /home/thies/public_html/ portal-HEAD/include/pw.db/table.php:670 some investigation showed that my prepared statement failed executing but not "preparing" (some expected unique constraint problem) - so my code would assign a diffferent value to the bound variables and try again (this time i would get the noted message). the code as it is now in pgsql_statement.c says (line 129 -) if (!stmt->executed) { /* we deferred the prepare until now, because we didn't * know anything about the parameter types; now we do */ S->result = PQprepare(H->server, S->stmt_name, S->query, stmt->bound_params ? zend_hash_num_elements (stmt->bound_params) : 0, S->param_types); but stmt->executed only seems to get set to when the execution was successful. my workaround is to add a new var to pdo_pgsql_stmt called is_prepared and use that as my protection against multiple prepares. re, thies