The following worked for me, however it's hard to give a definite answer, since full code was not provided.
Here is what I tested with, on my own server from an existing table.
Sidenote: Using :limit
or ?
after LIMIT
both worked and did not throw any errors.
<?php
$mysql_username = 'xxx'; // for DB
$mysql_password = 'xxx'; // for DB
try {
$pdo= new PDO('mysql:host=localhost;dbname=database_name', $mysql_username, $mysql_password);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$pdo->setAttribute( PDO::ATTR_EMULATE_PREPARES, false );
} catch (PDOException $e) {
exit( $e->getMessage() );
}
try {
$currPage = 2;
// $limit = 1;
$limit = $currPage * 25;
$sql = "SELECT * FROM animals LIMIT :limit,25";
$stmt = $pdo->prepare($sql);
$stmt->bindValue(':limit', $limit, PDO::PARAM_INT);
$stmt->execute();
$results = $pdo->query($sql);
// print_r($results);
} catch (PDOException $e) {
echo $e->getMessage();
}
$cols = $results->columnCount(); // Number of returned columns
echo 'Number of returned columns: '. $cols. '<br />';
echo '
<div align="center">
<center>
<table border="1" cellspacing="0" cellpadding="3">
<tr>
<td width="10%" bgcolor="#99CCFF"><p align="center">ID</td>
<td width="33%" bgcolor="#99CCFF"><p align="center">Breed</td>
<td width="34%" bgcolor="#99CCFF"><p align="center">Species</td>
</tr>
';
foreach($results as $row) {
echo "<tr><td width=\"10%\"><p align=\"center\">" . $row['id'] . "</td>\n<td width=\"33%\">" . $row['name'] . "</td><td width=\"33%\">" . $row['species'] . "</td>";
}
echo "\n";
echo "</tr>";
echo '
</table>
</center>
</div>
';
?>