2012-01-17 16 views
1

中にaddslashesのエラー:symfonyの - なぜなら私はDQLクエリ

$text = '%'.addslashes($text).'%'; 


    $images = $this->getDoctrine()->getEntityManager() 
     ->createQuery("SELECT img, cat, u 
         FROM AcmeMainBundle:Image img 
         JOIN img.category cat 
         JOIN img.user u 
         WHERE img.title LIKE '$text' OR img.description LIKE '$text' 
         ORDER BY img.id DESC") 
     ->getResult(); 

および$テキストは、それはそれを修正する方法エラー

[Syntax Error] line 0, col 150: Error: Expected end of string, got 'T' 500 Internal Server Error - QueryException

を投げるよりも、いくつかの 'を含みますか?

答えて

1
$images = $this->getDoctrine()->getEntityManager() 
     ->createQuery("SELECT img, cat, u 
         FROM AcmeMainBundle:Image img 
         JOIN img.category cat 
         JOIN img.user u 
         WHERE img.title LIKE :text OR img.description LIKE :text 
         ORDER BY img.id DESC") 
     ->setParameter('text', $text) 
     ->getResult(); 

それとも、これは試してみてください。

$text = "%".$text."%"; 
    $images = $this->getDoctrine()->getEntityManager() 
     ->createQueryBuilder() 
     ->select(array('img','cat','u')) 
     ->from('AcmeMainBundle:Image', 'img') 
     ->innerJoin('img.category', 'cat') 
     ->innerJoin('img.user', 'u') 
     ->where('img.title LIKE :title OR img.description LIKE :description') 
     ->orderBy('img.id','DESC') 
     ->setParameter('title', $title) 
     ->setParameter('description', $title) 
     ->getResult(); 
+0

それは何を変えるのか?前に試したことがありますが、私が ':text'かjust:textを使用したかどうかは分かりません。 BTW。今私はクエリの前に全体の部分を作成し、私はちょうど "... WHERE $検索"を行い、また "... WHERE:検索"を試みましたが、何も変わりません。 –

+0

ああ...私はそのパーセンテージを忘れています。 PDO - '$ text ="% "のように使用する必要があります。$ text。"% ";' – kuboslav

+0

「addslashes(...)」を削除することを意味しますか?上記の私のコードを参照してください。 –

関連する問題