$rowCount = $conn->query('SELECT COUNT(*) FROM Users');
echo '<pre>'.print_r($rowCount,1).'</pre>';
收益:
MysqLi_result Object
(
[current_field] => 0
[field_count] => 1
[lengths] =>
[num_rows] => 1
[type] => 0
)
…虽然我在PHPMyAdmin中看到的表有978行.
解决方法:
您正在使用print_r生成查询中的行数.您的查询只返回一行,即行数.
试试这个:
$rowCount = $conn->query('SELECT COUNT(*) as rowNumber FROM Users');
$row = $rowCount->fetch_assoc();
echo $row['rowNumber'];