Mysql 数据库中的表数始终返回1
每个人都建议使用Mysql 数据库中的表数始终返回1,mysql,Mysql,每个人都建议使用SELECT COUNT(*)FROM information\u schema.tables 如果我执行以下操作,则始终会返回“1”: $res=mysql_query("SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = 'usr_web275'"); $number_of_tables_in_database=mysql_num_fields($res)
SELECT COUNT(*)FROM information\u schema.tables
如果我执行以下操作,则始终会返回“1”:
$res=mysql_query("SELECT COUNT(*)
FROM information_schema.tables WHERE table_schema = 'usr_web275'");
$number_of_tables_in_database=mysql_num_fields($res);
echo $number_of_tables_in_database;
请执行以下操作:
$res=mysql_query("SELECT COUNT(*) FROM information_schema.tables WHERE table_schema = 'usr_web275'");
//Check if any row is returned or not.
if (!$res) {
echo "No data found";
}
else
{
$row = mysql_fetch_assoc($res); //Returns the row of the result
$number_of_tables_in_database = $row["count(*)"];
echo $number_of_tables_in_database;
}
为什么要获取“num_字段”而不是检索查询结果?因为我不确定我在做什么。正确的方法是什么?如果有人告诉你使用一个查询,那么只需要得到该查询的结果。不要获取该查询中的字段数。