为什么我得到结果$ result

时间:2012-11-07 09:11:40

标签: mysql

  

可能重复:
  Why do I get “Resource id #4” when I apply print_r() to an array in PHP?
  How do i “echo” a “Resource id #6” from a MySql response in PHP?

为什么我在$ result中得到“资源ID#6”?想要1或0:P

$sql = "SELECT * FROM members WHERE rchat=1 LIMIT 1";
$result = mysql_query($sql);

if (!$result) {
unlink($fn);
//$fn = $_SESSION['sess_user'].'.txt';
$fn = 'hittaingen.txt';
mysql_query("UPDATE members SET rchat=1 room='" . $_SESSION['sess_user'] . "' WHERE     user='" . $_SESSION['sess_user'] . "'");
}

else {
  //$fn = $result['room'].'.txt';
  $fn = 'hitta.txt';
  mysql_query("UPDATE members SET rchat=2 room='" . $result['room'] . "' WHERE user='" . $_SESSION['sess_user'] . "'");
  }

1 个答案:

答案 0 :(得分:2)

mysql_query()只返回结果对象的引用,而不是结果本身。因此,为了获得0或1,您必须首先使用例如mysql_fetch_array()

解析结果
$row = mysql_fetch_array( $result );

此外,您一定要查看PDOmysqli,因为mysql_X()函数被标记为已弃用且通常不被认为可以安全地防止SQL注入!