나는 PHP의 PDO를 사용하여 데이터베이스를 쿼리하여 사이트의 RESTful 백엔드를 구축하기 위해 슬림 프레임 워크를 사용하고 있습니다. PDO는 작은 따옴표 내 바인딩 된 매개 변수를 둘러싼되는 것처럼PDO 바운드 매개 변수에 작은 따옴표 추가하기
string(206) "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 ''10'' at line 1"`
것 같습니다 : 나는 준비된 명령문에 매개 변수를 바인딩하기 위해 노력하고있어 때, 나는 다음과 같은 오류가 발생합니다. 내 경로 코드는 다음과 같습니다.
$app->get("/members/next10/:offset", function($offset) use($app) {
$app->response()->header('Content-Type', 'application/json');
try {
$pdo = connectToDatabase();
$query = $pdo->prepare("SELECT * FROM `members` LIMIT 10 OFFSET :offset");
$query->bindParam(":offset", $offset, PDO::PARAM_INT);
$query->execute();
$result = $query->fetchAll(PDO::FETCH_ASSOC);
if (!empty($result)) {
echo json_encode($result);
} else {
$app->response()->status(404);
}
} catch (PDOException $d) {
$app->response()->status(500);
var_dump($d->getMessage());
}
});
내가 누락 된 항목이 있습니까? 나는 URL에서 :offset
을 움켜 잡으려고 시도하고 바인딩하기 전에 정수로 캐스팅하여 $offset
을 지정했지만 차이는 없습니다.
가능한 중복 http://stackoverflow.com/questions/5508993/pdo-limit-and-offset : 같은
경로 보인다 – fortune