当 MySQL 不返回任何内容时,$result 会是什么?
这可能看起来非常简单,但我一直收到各种错误,具体取决于我如何处理不返回任何内容的查询。
$query = "SELECT * FROM messages WHERE id > ".$messageId;
$result =mysql_query($query);
$time = time();
while(time()-$time<60 && $result==false)
{
$result = mysql_query($query);
}
if(result != false)
//Encode response
else
//return nothing
如何检查 mysql_query() 是否返回任何内容?
This might seem ridiculously simple, but I've been getting all kinds of error depending on how I handle a query that returns nothing.
$query = "SELECT * FROM messages WHERE id > ".$messageId;
$result =mysql_query($query);
$time = time();
while(time()-$time<60 && $result==false)
{
$result = mysql_query($query);
}
if(result != false)
//Encode response
else
//return nothing
How do I check whether my mysql_query() returned anything?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 mysql_num_rows().< 检查返回的行数。 /a>
假设你的循环是查询某些内容直到得到结果,那么
(不确定你在这里所做的是否是一个真正的好主意,因为它可能会给数据库服务器带来可怕的负担,但是这是一个不同的问题)
mysql_query() 将返回
false
仅适用于“真实”错误,例如拼写错误的查询或丢失的连接。You can check the number of returned rows using mysql_num_rows().
Presuming your loop is to query something until it gets a result, it would be
(not sure whether what you're doing here is a really good idea, as it is likely to put a terrible burden on the database server, but that's a different issue)
mysql_query() will return
false
only on "real" errors, e.g. a misspelled query or lost connection.