2012-09-18 65 views
0

PHP(Symfony的2.0)時:MySQL查詢例外,在查詢中使用正則表達式

$term = "3"; 

$query = $em->createQuery(
    "SELECT * FROM SoftsystemSupportBundle:Shop WHERE sid REGEXP '^$term'" 
); 

$shops = $query->getResult();  

拋出一個異常:

Error: Expected IdentificationVariable | StateFieldPathExpression | AggregateExpression | \"(\" Subselect \")\" | ScalarExpression, got '*'"

我想其中SID字段匹配正則表達式的所有實體。

任何想法最新怎麼了?

+1

無法幫助您直接回答,但爲何不嘗試使用SQLFiddle? – JvdBerg

回答

0

您正在濫用CreateQuery()方法返回的QueryBuilder對象。

您正在編寫DQL(Doctrine Query Language)而不是MySQL。 REGEXP不是DQL關鍵字,因此是錯誤。

你有同樣的問題這個職位:Using REGEXP in Doctrine 2.X ORM

給出了一個解決方案。