我有一个PHP页面,其中包含一些Mysqli,我试图从MySql转换。我想我已经正确地转换了大部分内容,但是当我尝试执行代码时,我收到以下错误消息(下面):
Connection was OK!
Warning: mysqli_stmt_num_rows() expects parameter 1 to be mysqli_stmt, object given in /quantityremaining5.php on line 25
9999
我对此有点新意,所以请保持温和 - 我做错了什么?谢谢!
<?php
include 'quantitytest_config.php';
// Create connection to MySQL
$link = mysqli_connect($hostname, $username, $password);
// Check connection
if (mysqli_connect_errno($link))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
} else { echo "Connection was OK!\n";}
//select a database to work with
$selected = mysqli_select_db($link, "grace59_countdown");
// or die("Could not select countdown");
// use if TWO SEPARATE columns for date and time
//execute the SQL query and return records
$result = mysqli_query($link,
"SELECT items
FROM cases
WHERE datetime<=NOW()
Limit 1 ");
if(mysqli_stmt_num_rows($result) == 0){
echo "9999";
} else {
//fetch tha data from the database
while ($row = mysqli_fetch_array($result)) {
echo "Quantity:".$row{'items'}."<br>";
}
}
//close the connection
mysqli_close($link);
?>
答案 0 :(得分:4)
使用mysqli_num_rows($result)
或$result->num_rows
。如名称所示,mysqli_stmt_num_rows()
旨在与mysqli_stmt
对象一起使用(由mysqli_prepare()
返回)。
请参阅documentation。