了解PHP中pg_last_error的错误消息

了解PHP中pg_last_error的错误消息,php,try-catch,Php,Try Catch,请看 如何解决准备语句中的以下错误消息? 我有一个index.php,通过许多处理程序将数据放入其中。以下错误消息出现在登录表单后的URL处 http://localhost/codes/index.php?ask_question&email=masi.masi@gmail.com&passhash_md5=202cb962ac59075b964b07152d234b70 这个问题的基础是。我得到了与Daniel相似的错误: Warning: pg_prepare() [f

请看


如何解决准备语句中的以下错误消息?

我有一个index.php,通过许多处理程序将数据放入其中。以下错误消息出现在登录表单后的URL处

http://localhost/codes/index.php?ask_question&email=masi.masi@gmail.com&passhash_md5=202cb962ac59075b964b07152d234b70
这个问题的基础是。我得到了与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中

我根据Daniel的建议将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']));

我仍然收到相同的错误消息。

是否准备自己的实现?它真的抛出异常吗

试试这个

if(is_null($result)) {
 throw new Exception("No valid Result");
}  
编辑:
在第一条评论中得到了答案

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

(对不起,下划线创建了cursiv格式)

如果您指的是prepare pg_prepare,那么pg_prepare不是我自己的实现。它似乎没有引发异常。我给了我一个警告。pg_last_error()很有用。它给了我一个错误:准备好的语句“query11”已经存在。我将所有query11的名称改为query777,但query777也有同样的错误。啊,好吧,你的问题标题有误导性:)我删除了$handle_login.php中的$dbconn,因为我在index.php中也有它。我还是有同样的错误。检查zed对你问题的评论。似乎很重要。你的postgre版本是什么?php手册说这只适用于7.4及以上版本。@Zed:i486 pc linux gnu上的PostgreSQL 8.3.7,由GCC-4.3.real(Ubuntu4.3.3-5ubuntu4)4.3.3编译。我不知道发生了什么,但在编写了更多代码并删除了旧的垃圾之后,问题消失了。-如果它回来,我会报告的谢谢你的回答!
"Any error in the prepare is available from pg_last_error()."