tags:

views:

116

answers:

1

Please, see this answer to see the main problem.


How can you solve the following error message in prepared statement?

I have a index.php to which I put data through many handlers. The following error message occurs at the following URL that is a URL after a login form.

http://localhost/codes/index.php?ask_question&[email protected]&passhash_md5=202cb962ac59075b964b07152d234b70

This question is based on this thread. I get a similar error as Daniel:

Warning: pg_prepare() [function.pg-prepare]: Query failed: ERROR: prepared statement "query11" already exists in /var/www/codes/handlers/handle_login_status.php on line 6
Prepared statement failed.

in the code *handle_login.php*

$dbconn = pg_connect("host=localhost port=5432 dbname=masi user=masi password=123");
$result = pg_prepare($dbconn, "query11", "SELECT passhash_md5 FROM users
             WHERE email=$1;");
$passhash_md5 = pg_execute($dbconn, "query11", array($_POST['email']));

I changed the *handle_login.php* by Daniel's pieces of advice to

 $dbconn = pg_connect("host=localhost port=5432 dbname=masi user=masi password=123");
 try{
     $result = pg_prepare($dbconn, "query11", "SELECT passhash_md5 FROM users
         WHERE email=$1;");
     if($result){
         $result->rayPrepared['query11'] = true;    // I changed $this to $result
     }else{
         throw new Exception('Prepared statement failed.');
     }
 }catch(Exception $e){
     echo $e->getMessage();
 }
 $passhash_md5 = pg_execute($dbconn, "query11", array($_POST['email']));

I still get the same error message.

+1  A: 

Is prepare your own implementation? Does it actually throw an exception?

try this

if(is_null($result)) {
 throw new Exception("No valid Result");
}

Edit:
Got the answer in the first comment

"Any error in the prepare is available from pg_last_error()."

pg_ last _ error (sorry, the underline create the cursiv format)

Henrik P. Hessel
If you mean by prepare pg_prepare, then pg_prepare is not my own implementation. It does not seem to throw an exception. I throws me a warning.
Masi
You can find it here http://fi2.php.net/manual/en/function.pg-prepare.php
Masi
I added your first code. I get the same error as before.
Masi
pg_last_error() is useful. It gives me ERROR: prepared statement "query11" already exists. I changed the names of all query11 to query777, but I get the same error for query777.
Masi
Ah, okay, your question title is misleading :)
Henrik P. Hessel
I removed $dbconn in $handle_login.php because I have it also at index.php. I get the same error still.
Masi
I renamed the $dbconn to $dbconn2. I changed too all $dbconn to $dbconn2 in *handle_login.php*. I get still the same error.
Masi
check zed's comment on your question. seems to be important.
Henrik P. Hessel
I answered the comment.
Masi