As you can see I’m trying to fetch rows from table while using prepared statements.
$stmt = $conn->prepare("SELECT * FROM table ORDER BY date DESC LIMIT ?, 10");
$stmt->bindParam(1, $row_start, PDO::PARAM_INT);
$stmt->execute();
while($row = $stmt->fetch()) {
echo $row['title'];
echo $row['name'];
}
It doesn’t echo anything.
Edit: var_dump is showing this log :
“You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use
near ”0′, 10′ at line 1″ }
Edit 2: Here is how I declare my $row_start
$row_start = "0";
if (isset($_GET['page']) && is_numeric($_GET['page']) && $_GET['page'] != "0" )
{
$row_start = $_GET['page'];
if ($row_start == "1") {
$row_start = "0";
}else{
$row_start = ($row_start-1) * 10;
}
}
By default, the value type will be string.
You can set it to an integer like this:
Update:
Even though you are forcing it to INT, it’s still passing it as a string.
Look at your error message:
And specifically the ending
'after 0, indicating it is a string.Update
Manually typecasting the variable is needed, even if you pass the expected PDO type: