1

我有一个 PHP 页面,其中包含一些我试图从 MySql 转换的 Mysqli。我想我已经正确转换了大部分内容,但是当我尝试执行代码时收到以下错误消息(如下):

    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);
?>
4

1 回答 1

4

使用mysqli_num_rows($result)$result->num_rows。顾名思义,mysqli_stmt_num_rows()旨在与mysqli_stmt对象一起使用(由 返回mysqli_prepare())。

请参阅文档

于 2013-04-19T01:23:29.653 回答