mysql_num_rows
检索结果集中的行数。该命令仅对像SELECT或SHOW这样的返回实际结果集的语句有效。
如果没有匹配,那么零将是返回值并且有效FALSE
。
$result = mysql_query($query);
if(mysql_num_rows($result))
{ //-- non-empty rows found fitting your SQL query
while($row = mysql_fetch_array($result))
{//-- loop through the rows,
//-- each time resetting an array, $row, with the values
}
}
如果你只是退出数据库,这是一切都很好。如果更改或从数据库中删除行,想知道有多少人受到它的影响...
要检索受一个INSERT,UPDATE的行数,替换或删除查询,使用mysql_affected_rows()
。
$result = mysql_query($query);
if(mysql_affected_rows())
{ //-- database has been changed
}
//-- if you want to know how many rows were affected:
echo 'Rows affected by last SQL query: ' .mysql_affected_rows();
mysql_query()
只会返回FALSE
如果查询失败。即使您没有行但会成功查询数据库,它将返回TRUE
。
在代码中使用`$ _CLEAN`看起来非常可疑。看看这里为什么这是一个坏主意:http://stackoverflow.com/questions/6164522/will-this-code-actually-work-against-sql-injection – Johan 2011-05-28 21:59:34