簡體   English   中英

如何解決PostgreSQL / PHP中的“資源ID#8”錯誤消息?

[英]How can I resolve the “Resource ID #8” error message in PostgreSQL/PHP?

如何解決以下代碼中的Resource ID#8-錯誤消息?

該錯誤顯然意味着我的SQL語句中有錯誤。 但是,我看不到它。

 $result = pg_prepare($dbconn, "query1", "SELECT user_id FROM users 
     WHERE email = $1;");
 $result = pg_execute($dbconn, "query1", array("test@gmail.com"));
 // to read the value

 while ($row = pg_fetch_row($result)) {
     $user_id = $row[0];
 }

嘗試echo $result時收到錯誤消息。

不要echo $result這是一個記錄集,而不是要echo的實際值。 不過,您應該能夠在while循環中echo $row[0]

while ($row = pg_fetch_row($result)) {
     $user_id = $row[0];
     echo $user_id . '<br/>';
 }

順便說一下,您發布的代碼沒有錯-語法很好。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM