我有一個pdo語句來選擇行並在數組中返回它們。我正在使用分頁顯示每頁12個結果。如果我直接輸入LIMIT 12, 12
,而不是LIMIT ?, ?
該聲明正常工作。PDO bindParam不允許語句返回結果
我在爲兩個變量的bindParam做錯了什麼?
這兩個變量都包含正確的數據。
繼承人我使用的功能:
// Retrieve active posts
function retrieve_active_posts(){
//test the connection
try{
//connect to the database
$dbh = new PDO("mysql:host=db2940.oneandone.co.uk;dbname=db348699391","xxx", "xxx");
//if there is an error catch it here
} catch(PDOException $e) {
//display the error
echo $e->getMessage();
}
// Get all the posts
$stmt = $dbh->prepare(" SELECT p.post_id, post_year, post_desc, post_title, post_date, img_file_name, p.cat_id
FROM mjbox_posts p
JOIN mjbox_images i
ON i.post_id = p.post_id
AND i.cat_id = p.cat_id
AND i.img_is_thumb = 1
AND post_active = 1
ORDER BY post_date
DESC
LIMIT ?,?");
$stmt->bindParam(1, $limit);
$stmt->bindParam(2, $offset);
$stmt->execute();
while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$resultarray[] = $row;
}
return $resultarray;
}
非常感謝
你可以添加的var_dump'輸出($極限,$偏移) ;'? – hek2mgl 2013-04-06 16:33:44
@ hek2mgl NULL NULL NULL – crm 2013-04-06 16:35:58
@crm檢查我的答案;) – hek2mgl 2013-04-06 16:37:34