繁体   English   中英

PDO准备好的语句返回false

[英]PDO prepared statement returning false

知道为什么这返回假吗?

用于调用代码的函数:

$product = new Product;
$allProducts = $product->getProducts(12);

我正在调用的函数:

public function getProducts($limit)
    {
        $values = array($limit);
        $statement = $this->conn->prepare('SELECT * FROM sellify_items ORDER BY id DESC LIMIT ?');
        $statement->execute($values);
        $result = $statement->fetchAll();
        if ($result) {
            return $result;
        }
        return false;
    }

编辑:更新功能

public function getProducts($limit)
{
    $values = array(intval($limit));
    $statement = $this->conn->prepare('SELECT * FROM sellify_items ORDER BY id DESC LIMIT ?');
    $statement->bindValue(0, $limit, PDO::PARAM_INT);
    $statement->execute($values);
    $result = $statement->fetchAll();
    if ($result) {
        return $result;
    }
    return false;
}

试试这个(注意强制转换为int):

$statement->bindValue(0, (int) $limit, PDO::PARAM_INT);

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM