[英]update mysql_num_rows to new Mysqli standard: mysqli_stmt_num_rows
I have a PHP page with some Mysqli that I am attempting to convert from MySql. 我有一个PHP页面,其中包含一些我试图从MySql转换的Mysqli。 I think I've converted most of it correctly, but I am getting the following error message when I try to execute the code (below): 我想我已经正确地转换了大部分内容,但是当我尝试执行代码时,我收到以下错误消息(如下所示):
Connection was OK!
Warning: mysqli_stmt_num_rows() expects parameter 1 to be mysqli_stmt, object given in /quantityremaining5.php on line 25
9999
I'm a bit new to this, so please be gentle - what is that I'm doing wrong? 我对此有点新意,所以请保持温和 - 我做错了什么? thanks! 谢谢!
<?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);
?>
Use mysqli_num_rows($result)
or $result->num_rows
. 使用mysqli_num_rows($result)
或$result->num_rows
mysqli_num_rows($result)
$result->num_rows
。 As the name indicates, mysqli_stmt_num_rows()
is intended to be used with a mysqli_stmt
object (as returned by mysqli_prepare()
). 如名称所示, mysqli_stmt_num_rows()
旨在与mysqli_stmt
对象一起使用(由mysqli_prepare()
返回)。
See the documentation . 请参阅文档 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.