의 토큰 수와 일치하지 않습니다. 둘 이상의 단어를 사용할 때이 검색 방법이 올바르게 작동합니다. 단 하나 개의 단어가있는 경우 그러나 그것은 오류를 제공합니다 $stmt
의SQLSTATE [HY093] : 잘못된 매개 변수 번호 : 바운드 변수의 수가
SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens in.
var_dump
을 제공합니다
object(PDOStatement)#5 (1) {
["queryString"]=> string(117) "SELECT event_id, event_name FROM adrenaline_junkies_uk_events WHERE (`event_name` REGEXP ?) AND event_id <> ? LIMIT 3"
}
바운드 변수를 추가 할 것으로 보인다. 내가 여기서 무엇을 놓치고 있니?
을 heres 방법 :
public function getSimilarEvents($event_id, $nameArray) {
$uniqueWords = array();
// list of common words we dont want to search by
$commonWords = array('a','able','you\'ve','z','zero');
// Build array of words that dont match common words
var_dump($uniqueWords = array_diff($nameArray, $commonWords));
// Count how many words there are
$wordCount = count($uniqueWords);
// create where string to add to query
$where_string = implode(" OR ", array_fill(0,$wordCount, "`event_name` REGEXP ?"));
// build start of mysql query
$query = "SELECT event_id, event_name FROM adrenaline_junkies_uk_events WHERE ($where_string) AND event_id <> ? LIMIT 3";
$stmt = $this->dbh->prepare($query);
$x = 0;
foreach($uniqueWords AS $index => $word){
$stmt->bindValue($index+1, "[[:<:]]".$word."[[:>:]]", PDO::PARAM_STR);
$x++;
}
$stmt->bindValue($x+1, $event_id, PDO::PARAM_INT);
$stmt->execute();
var_dump($stmt);
if($stmt->rowCount() > 0){
return $stmt->fetchAll();
}else{
return $stmt->rowCount();
}
}
인터넷을 통한 검색을 시작하기 전에 먼저 자신의 검색을 작성 하시겠습니까? 또는 엔진으로 나열된 유사한 질문에 대한 탐색 기술을 적어도 향상 시키십니까? –
내 질문이 어떻게 든 유효하지 않습니까? – crm
당신은'$ x'를 아무 곳이나 선언하지 않습니다. –