PDO Prepare Statement Limit Not Working
php
Solution
Solved.
$sth->bindParam(':limit', $limit, PDO::PARAM_INT);
Problem
I'm attempting to limit the amount of results returned from an SQL query, but for some reason it's returning NULL. If I remove the LIMIT, all works fine. I've tested the query in Sequel Pro and it also works fine with the LIMIT. Am I doing something wrong here? ``` public static function getMostViewedPictures($limit = 5) { $dbh = self::connectToDatabase(); $sql = "SELECT picture.`title`, picture.`description`, picture.`slug`, picture.`image`, picture.`timestamp`, picture.`views`, category.category as category FROM picture LEFT JOIN category ON picture.category_id = category.id ORDER BY picture.views ASC LIMIT 0, :limit"; $sth = $dbh->prepare($sql); $sth->execute(array(':limit' => $limit)); if($results = $sth->fetchAll(PDO::FETCH_OBJ)) { $pictures = array(); foreach($results as $result) { $pictures[] = new Picture( $result->title, $result->description, $result->slug, $result->timestamp, $result->category, $result->views, $result->image ); } return $pictures; } else { return null; } } ```