2016-12-29 1 views
1

전체 텍스트 검색 쿼리에 문제가 있습니다. 중요한 경우 Symfony (2.8) 컨트롤러 내부에서 전송됩니다. 코드는 다음과 같습니다.Symfony/MySQL : 특수 문자에 대한 전체 텍스트 검색 구문 오류

// not processed text (apart from multiple spaces) from form: 
$searchTerm = preg_replace('!\s+!', ' ', trim($data['query'])); 
// for full-text search: 
$searchTermPhrase = str_replace(' ', '* ', $searchTerm) . '*'; 

$entityManager = $this->getDoctrine()->getManager(); 
// as far as I remember, query taken from StackOverflow after some tests 
$statement = $entityManager->getConnection() 
          ->prepare(
          "SELECT COUNT(id) AS books_count 
           FROM book 
           WHERE 
           MATCH(title) AGAINST (:searchTermPhrase IN BOOLEAN MODE) > 5 
           AND active = true 
           "); 
$statement->execute(array('searchTermPhrase' => $searchTermPhrase)); 

$titlesCount = $statement->fetch(); 
$titlesCount = $titlesCount['books_count']; 

이제는 훌륭합니다. 대부분의 시간. 사용자가 내부의 특수 문자를두고 경우에, 등 예를 (title), "title"를 들어, 실패 :

SQLSTATE[42000]: Syntax error or access violation: 
1064 syntax error, unexpected $end, expecting 
FTS_TERM or FTS_NUMB or '*' 

나는 그것을 얻지 않는다, 나는 매개 변수화 쿼리를 사용하여 자동으로 이러한 경우의주의해야 ... ? 나는 문제를 일으키는 영숫자가 아닌 문자 나 테스트를 모두 없애고 싶지는 않지만 아이디어가 없습니다.

답변

관련 문제