我正在尝试使用以下代码获取表中的总行数:
$count = mysqli_query($con, "SELECT COUNT(*) AS total FROM random_codes");
$count = mysqli_fetch_object($count);
$count = $count->total;
echo "count is $count<br />";
但回声始终是“count is”,后面没有任何值。在 phpMyAdmin 中运行相同的 SQL 代码会返回请求的总行数(超过 2000),因此问题可能出在 php 代码中。亲爱的响应者,我是 php 和 sql 的新手,所以请详细说明和/或将我链接到文档。谢谢..
编辑:尝试错误检查,没有错误显示
$result = mysqli_query($con, "SELECT COUNT(*) AS total FROM random_codes");
echo mysqli_error($con);
$obj = mysqli_fetch_object($result);
$count = $obj->total;
echo "count is $count<br />";