Reputation: 127
Any idea why this is returning false?
Code using to call function:
$product = new Product;
$allProducts = $product->getProducts(12);
Function I'm calling:
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;
}
Edit: Updated function
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;
}
Upvotes: 0
Views: 570
Reputation: 1668
Try this (note casting to int):
$statement->bindValue(0, (int) $limit, PDO::PARAM_INT);
Upvotes: 1