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

- Thread: https://externals.io/message/21075
- Original archive: https://news-web.php.net/php.internals/21075
- Started by Thies C. Arntzen on 2005-12-07T13:16:40+00:00
- Messages: 1
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #21075 — Thies C. Arntzen — 2005-12-07T13:16:40+00:00

URL: https://externals.io/message/21075#21075

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
