초보자로서, 나는 PHP MySQL 튜토리얼을 따라 왔으며, 일반적인 MySQL PHP 함수의 사용을 조언했다. 그러나 PDO가 더 나은 대안이라고 들었 기 때문에 필자는 코드를 변환 해왔다.MySQL PDO 쿼리 구문 오류? parameters
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 '? WHERE id=? AND ?' at line 1
왜 즉 :
$query = $uspdb->prepare("SELECT post_id, is_approved, reports FROM ? WHERE id=? AND ?");
$query->bindValue(1, $table, PDO::PARAM_INT);
$query->bindValue(2, $id, PDO::PARAM_INT);
$query->bindValue(3, checkPermission("comment_moderation"),PDO::PARAM_BOOL);
$query->execute;
$result = $query->fetch(PDO::FETCH_ASSOC);
첫 번째 줄은 다음과 PDO 예외가 발생합니다 : 난 그냥 다음과 같은 문제에 달렸다? 구문에 무엇이 잘못 될 수 있는지 전혀 알지 못합니다. tutorial I'm reading은 ". $ id"보다는 매개 변수를 추가하기 위해 bindValue 나 execute (array (stuff))를 사용해야한다고 알려줍니다. 좋아하는 사람은 더 안전하기 때문에 어떤 이유로 든 작동하지 않습니다.
테이블 이름을'PDO :: PARAM_INT'로 바인드합니다. 틀렸을 것입니다. –