PHP中的MySQL SELECT查询不会返回与直接查询数据库相同的结果

时间:2019-02-21 22:34:41

标签: php mysql

我正在玩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

0 个答案:

没有答案