以下是我的方法的类:
class BidsInfoRepository extends EntityRepository
{
public function findbidWinnerQuery($productId) {
return $this->getEntityManager()
->createQuery("SELECT w FROM ReverseAuctionReverseAuctionBundle:BidsInfo w where w.ProductInfo = ***$productId*** GROUP BY w.bAmount HAVING COUNT(w) = 1")
->setMaxResults(1)
->getResult()
;
}
}
变量 $productId 具有以下用连字符分隔的格式值: 5cbfde50-50b9-11e5-9612-752c7cea21e5,
显然它不喜欢这种格式,事实上'cbdfe50'包含在用连字符分隔的字符串中,出于某种原因,我认为连字符停止了进程,但我不知道如何让mysql来处理用连字符分隔的长字符串,而不是返回我的问题标题中提到的错误。任何想法?谢谢。
附:我也尝试过使用“like '$productId'”,但它不起作用。
最佳答案
您只是忘记了引号:
"SELECT w FROM ReverseAuctionReverseAuctionBundle:BidsInfo w where w.ProductInfo = '5cbfde50-50b9-11e5-9612-752c7cea21e5' GROUP BY w.bAmount HAVING COUNT(w) = 1"
另请记住,您应该在 sql 查询中正确转义字符串,以避免 sql 注入(inject)。
关于mysql - 语法错误第 0 行,第 83 列 : Error: Expected end of string, 得到 'cbfde50',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32351087/