检查mysql_query是否返回任何东西 [英] Checking if mysql_query returned anything or not
本文介绍了检查mysql_query是否返回任何东西的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
$query = "SELECT * FROM `table`";
$results = mysql_query($query, $connection);
如果表"没有行.什么是最简单的检查方法??
If 'table' has no rows. whats the easiest way to check for this.?
推荐答案
您可以使用 mysql_num_rows($ results)检查是否返回了0行,或使用这种更快的替代方法:
You could use mysql_num_rows($results) to check if 0 rows were returned, or use this faster alternative:
$query = "SELECT COUNT(*) AS total FROM table";
$results = mysql_query($query, $connection);
$values = mysql_fetch_assoc($results);
$num_rows = $values['total'];
这篇关于检查mysql_query是否返回任何东西的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文