在PHP中,mysqli_num_rows函数用于获取结果集中的行数。它的使用方式如下:
$conn = new mysqli("localhost", "username", "password", "database");
$query = "SELECT * FROM table";
$result = mysqli_query($conn, $query);
$rowCount = mysqli_num_rows($result);
echo "总共有 " . $rowCount . " 行数据";
完整的示例代码如下:
$conn = new mysqli("localhost", "username", "password", "database");
$query = "SELECT * FROM table";
$result = mysqli_query($conn, $query);
$rowCount = mysqli_num_rows($result);
echo "总共有 " . $rowCount . " 行数据";
注意:在使用mysqli_num_rows函数之前,需要先执行mysqli_query函数来执行查询并获取结果集。使用mysqli_num_rows函数之前,还需要确保数据库连接已经建立。