준비 문을 사용하여 개체 변수에 인수로 전달 된 클래스 개체 속성을 사용하여 자리 표시 자 값을 설정하려고합니다. __construct 함수. 그러나 나는 솔기가 자리 표시 자 값에 대해 하나의 매개 변수 만 가질 때 2 개의 매개 변수에 대한 필요성을 지정하는 오류가 발생합니다.PHP - PDO Prepared Statement, "경고 : PDOStatement :: bindParam()에 2 개 이상의 매개 변수가 필요합니다."
CODE :
<?php include ('connection.inc.php');
class Team {
// Remember to switch back to private!
private $database;
public $statement = 'SELECT * FROM members ORDER BY :full_name';
public $order;
public $query;
private $result;
public function __construct($database, $order) {
$this->database = $database;
$this->order = $order;
$this->query = $this->database->prepare($this->statement);
$this->query->bindParam(array('full_name', $this->order));
$this->query->execute();
}
public function getMember() {
$this->result = $this->query->fetch(PDO::FETCH_ASSOC);
return $this->result;
}
public function id() {
echo $this->result['id'];
}
public function fullName() {
echo $this->result['full_name'];
}
public function alias() {
echo $this->result['alias'];
}
public function abilities() {
echo $this->result['abilities'];
}
};
$test = new Team($database, 'full_name');
?>
ERRORS :
경고 : PDOStatement가 :: bindParam()가 기대 (1)
치명적인 오류에 주어진 적어도 2 개 개의 파라미터 : 'SQLSTATE [HY093] : 잘못된 매개 변수 번호 : 매개 변수 없음'메시지와 함께 'PDOException'오류가 잡히지 않았습니다. 이 오류를 제거
$this->query->bindParam(':full_name', $this->order));
: ERS는 내가 내 bindParam()
문을 변경,
솔루션 '@Daerik에
감사를 구속했다.
감사합니다, 모두 오류를 제거 :
또는 단지 하나
는, 배열을 통과하지 못한,bindParam()
는 두 개의 인수가 필요합니다. 그러나'gettMember()'메소드를 사용하여 sql 질의를 반복 할 때'ORDER BY ': full_name'문장을 무시하고'id' 컬럼을 사용하여 엔트리를 정렬합니다. 준비된 성명서에 잘못이 있습니까? –@ FrederickM.Rogers 당신은'ORDER BY' 문에서 컬럼을 사용하고자 할 것입니다. 문자열을 할당하면 모두를 동일한 값으로 비교하고 인덱스를 기본값으로 비교합니다. 자세한 내용은 http://dev.mysql.com/doc/refman/5.7/en/order-by-optimization.html을 참조하십시오. – Daerik
읽어 주시고 필요한 조정을 해 주셔서 감사합니다! –