1
준비된 SQL 문에서 매개 변수를 바인딩하려고하는데, 그렇게 할 수 없습니다. 내가 가진 코드는 다음과 같습니다prepared statement 값이 바인딩되지 않았습니다.
function accountGet($database,$target,$index,$index_value) {
$sql = 'SELECT :target from accounts WHERE :index = :index_value';
$query = $database->prepare($sql);
$query->execute(array(
':target' => $target,
':index' => $index,
':index_value' => $index_value
));
print_r($query);
}
매개 변수는 구속하지 않는 것. 반환 된 진술을 받고 있습니다 : PDOStatement Object ([queryString] => SELECT :target from accounts WHERE :index = :index_value)
어떻게 수정합니까?
간단한, 당신은 SELECT에서 열을 바인딩 할 수 없습니다. 'SELECT : target' <= uh-huh. –
@ Fred-ii- thanks. 나는 그것을 '$ sql ='SELECT '. $ target.'으로 변경했다. 계정에서 어디에서 : index = : index_value ';'작동하지만,': index'와'index_value'는 여전히 바인드되지 않습니다. – bsapaka
당신은 천만에요. 그것은'index'가 예약 된 MySQL 단어인데, 그 이유는 http://dev.mysql.com/doc/refman/5.5/en/reserved-words.html 가능성이 가장 높기 때문입니다. 시도하고 다른 이름을 선택하십시오. 또한,'WHERE : index'를 할 수 있는지 확신 할 수 없다. –