PDO准备好的声明返回false

时间:2015-05-03 22:48:13

标签: php pdo prepared-statement

知道为什么这会返回false?

用于调用函数的代码:

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

功能I' m:

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;
}

1 个答案:

答案 0 :(得分:1)

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

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