Mysqli $ stmt-> fetch返回false

时间:2014-06-17 17:02:15

标签: 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 ($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;
}

第二个'无法执行查询'。抛出异常。我通过在第二条错误消息的末尾添加随机字符来测试它,以区分它。

非常感谢任何帮助!如果我没有提供足够的信息,请告诉我,我会很乐意提供更多信息。

0 个答案:

没有答案