問題描述
我已經搜索了可能的解決方案.我嘗試過循環以及嘗試 mysql_fetch_assoc 和 mysql_fetch_array 的變體,但我仍然得到資源 ID #5: 0: 錯誤.
I've searched about possible solutions to this. and I've tried looping as well as trying the variants of mysql_fetch_assoc and mysql_fetch_array but I'm still getting the Resource id #5: 0: error.
這是我認為會產生錯誤的代碼.
Here's my code which I think generates the error.
<?php
mysqlc();
$email = GetSQLValueString($_SESSION['user'], "text");
$query = sprintf("SELECT * FROM newmember WHERE email = %s",$email);
$res = mysql_query($query) or die('Query failed: ' . mysql_error() . "<br />
$sql");
$row = mysql_fetch_assoc($res);
?>
推薦答案
"Resource id #5: 0" 不是錯誤.這意味著您嘗試 echo $res
而不是嘗試使用 $row
變量,例如 $row[column] 用于 fetch_assoc,$row[0] 用于 fetch_row, fetch_array 中的一個/兩個.
"Resource id #5: 0" is not an error. It means that you tried to echo $res
instead of trying to use the $row
variable, such as $row[column] for fetch_assoc, $row[0] for fetch_row, either/both for fetch_array.
其他答案解釋mysql_fetch_*的使用
The other answers explain the use of mysql_fetch_*
此外,不推薦使用 mysql_*.您應該改用 mysqli_* 或 PDO 函數.
Also, mysql_* is deprecated. You should use mysqli_* or PDO functions instead.
這篇關于mySQL 查詢返回資源 ID #5的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!