2009-08-12 61 views
0

如何解決以下代碼中的Resource ID #8-錯誤消息?如何在PostgreSQL/PHP中解決「資源ID#8」錯誤消息?

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

$result = pg_prepare($dbconn, "query1", "SELECT user_id FROM users 
    WHERE email = $1;"); 
$result = pg_execute($dbconn, "query1", array("[email protected]")); 
// to read the value 

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

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

回答

3

不要echo $result - 這是一個記錄集,而不是實際值爲echo ed。你應該能夠echo $row[0]while循環中,雖然:

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

沒有什麼錯,你貼出來,順便碼 - 語法是罰款。

+0

我收到相同的錯誤消息。 – 2009-08-12 02:53:19

+0

當直接針對MySQL運行時,此查詢的結果如下:'從email ='test @ gmail.com''的用戶中選擇user_id – Eric 2009-08-12 03:02:06

+0

@Eric:它給出1. – 2009-08-12 03:29:17

相關問題