我正在玩PHP。我的问题是,我使用COUNT()函数的SELECT查询仅返回一行,但是当我直接通过phpmyadmin查询数据库并回显其内容时,同一查询将返回正确的行数(三)。
$servername = "localhost";
$username = "admin_browser";
$password = "BrowserPw";
$dbname = "admin_database";
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT COUNT('$field') FROM $table";
echo ($sql . "<br />");
$max = mysqli_num_rows(mysqli_query($conn, $sql));
echo ($max . " rows returned <br />"); // 1 rows returned