PDO bindParam erlaubt keine Anweisung, Ergebnisse zurückzugeben
Ich habe eine pdo-Anweisung, um Zeilen auszuwählen und sie in einem Array zurückzugeben. Ich verwende die Paginierung, um 12 Ergebnisse pro Seite anzuzeigen. Wenn ich direkt eingebeLIMIT 12, 12
, anstattLIMIT ?, ?
Die Anweisung funktioniert ordnungsgemäß.
Was mache ich falsch mit dem bindParam für beide Variablen?
Beide Variablen enthalten die richtigen Daten.
Hier ist die Funktion, die ich benutze:
// 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;
}
Danke vielmals