【发布时间】:2009-08-10 03:08:41
【问题描述】:
请参阅this answer to see the main problem。
如何解决prepared statement中的以下错误信息?
我有一个 index.php,我通过许多处理程序将数据放入其中。以下错误消息出现在以下 URL 中,该 URL 是登录表单后的 URL。
http://localhost/codes/index.php?ask_question&email=masi.masi@gmail.com&passhash_md5=202cb962ac59075b964b07152d234b70
此问题基于this thread。我收到与 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.
在代码中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']));
我按照丹尼尔的建议把handle_login.php改成了
$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']));
我仍然收到相同的错误消息。
【问题讨论】:
-
你的 postgre 版本是什么? php 手册说这仅适用于 7.4 及更高版本。
-
@Zed:i486-pc-linux-gnu 上的 PostgreSQL 8.3.7,由 GCC gcc-4.3.real (Ubuntu 4.3.3-5ubuntu4) 4.3.3 编译
-
我不知道发生了什么,但是在编写更多代码并删除旧垃圾之后,问题就消失了。 - 如果它回来,我会报告。 - 感谢您的回答!