Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Mysqli$stmt->fetch返回false_Php_Mysql_Exception_Mysqli_Fetch - Fatal编程技术网

Php Mysqli$stmt->fetch返回false

Php Mysqli$stmt->fetch返回false,php,mysql,exception,mysqli,fetch,Php,Mysql,Exception,Mysqli,Fetch,我正在写一个网站,它要求我允许用户创建带有特定字段的项目。然后,这些用户可以查看项目,但是从数据库获取项目的后端函数被破坏。出于某种原因,语句准备并执行,但当我获取结果时,返回false。调用$stmt->errno时,返回的错误号为0。这是我的密码: function item_get($mysqli, $iid) { if ($mysqli == null) throw new Exception('Could not connect to database.'); if (

我正在写一个网站,它要求我允许用户创建带有特定字段的项目。然后,这些用户可以查看项目,但是从数据库获取项目的后端函数被破坏。出于某种原因,语句准备并执行,但当我获取结果时,返回false。调用$stmt->errno时,返回的错误号为0。这是我的密码:

function item_get($mysqli, $iid) {
    if ($mysqli == null) throw new Exception('Could not connect to database.');
    if ($iid == null || $iid < 1) throw new Exception('Item id(iid) is required.');

    $stmt = $mysqli->prepare('SELECT i.iid, i.uid, i.name, i.price, i.condition, i.location, i.image_urls, i.description, i.category, i.subcategory, i.interval, i.deposit, i.terms_of_service, i.cancel_policy, i.min_rental_time, i.up_front, i.house_rules, i.room_type
        FROM items AS i WHERE i.iid = ?;');

    if (!$stmt)
        throw new Exception('Could not connect to database.');

    $iid = $mysqli->real_escape_string($iid);
    $stmt->bind_param('i', $iid);

    $stmt->bind_result($item_iid, $uid_creator, $name, $price, $condition, $location, $image_urls, $description, $category, $subcategory, $interval, $deposit, $terms_of_service, $cancel_policy, $min_rental_time, $up_front, $house_rules, $room_type);

    if (!$stmt->execute())
        throw new Exception('Could not execute query.');

    if (!$stmt->fetch())
        throw new Exception('Could not execute query.');

    if ($item_iid == null)
        return null;

    $item = new Item($item_iid, $uid_creator, stripslashes($name), $price, stripslashes($description), stripslashes($location), $image_urls, $category, stripslashes($subcategory), $interval, stripslashes($condition), $deposit, stripslashes($terms_of_service), stripslashes($cancel_policy), stripslashes($min_rental_time), $up_front, stripslashes($house_rules), $room_type);
    return $item;
}
第二个“无法执行查询”。引发异常。我通过在第二条错误消息的末尾添加随机字符来区分它来测试它


非常感谢您的帮助!如果我没有提供足够的信息,请让我知道,我很乐意提供更多信息。

这是否仅仅是因为我准备的声明没有结果?我刚刚意识到,在没有剩余结果的情况下,fetch如何返回false。如果没有返回行,fetch将返回false。这不是一个错误状态,所以您不应该在那里抛出异常。@MichaelBerkowski非常感谢,我将检查我的查询!我正试图完成一件我的同事开始的事情,但在他完成之前就辞职了,所以他的风格让我很反感。没问题。这是一个常见的错误。您对$item_iid==null的检查应该足够了。