簡體   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