此查询:
$this->getEntityManager()
->createQuery("SELECT k FROM FooBarBundle:Kode k WHERE k.kode LIKE :keyword OR k.nama LIKE :keyword ORDER BY k.kode ASC")
->setParameter("keyword", "%$keyword%")
->setMaxResults($limit)
->setFirstResult($offset)
->getResult();
生成以下SQL错误:
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'OFFSET 0' at line 1
但如果删除setFirstResult($offset)
行,则可以正常工作。是否有任何解决方法,而不是升级整个Doctrine库(补丁可能没问题)?
答案 0 :(得分:1)
我认为你必须删除
ORDER BY k.kode ASC
从您的查询并使用如下方法设置它:
$this->getEntityManager()
->createQuery("SELECT k FROM FooBarBundle:Kode k WHERE k.kode LIKE :keyword OR k.nama LIKE :keyword")
->setParameter("keyword", "%$keyword%")
->setMaxResults($limit)
->setFirstResult($offset)
->orderBy("k.kode")
->getResult();