$sql = "SELECT sql_calc_found_rows * FROM members".
" ORDER BY username LIMIT :startRow, :numRows";
try {
$st = $conn->prepare($sql);
$st->bindParam(":startRow", $startRow, PDO::PARAM_INT);
$st->bindParam(":numRows", $numRows, PDO::PARAM_INT);
$st->execute();
} catch (PDOException $e) {
die("Query failed: " . $e->getMessage());
}
Ở đây tôi nhận được lỗi:PHP PDO lỗi khi sử dụng placeholders trong LIMIT khoản của một truy vấn MySQL
Query failed: SQLSTATE[42000]: Syntax error or access violation: 1064 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 ''5'' at line 1.
Các LIMIT :startRow, :numRows
có vấn đề trong :numRows
.
Tôi đã thử cả hai $st->bindParam
và $st->bindValue
, cả hai đều không hoạt động.
Bạn có thể thử để loại bỏ trống thứ giữa ': startRow,: numRows' – Jens
giá trị của $ trật tự? –
SELECT sql_calc_found_rows * FROM ?? cái gì thế này? –