我想运行这个 Doctrine Query Builder 查询:
$repository = $this->getDoctrine()->getRepository('MyBundle:Usage');
$usage_q = $repository->createQueryBuilder('u')->where('u.var = \'warranty\'');
$usage_result = $usage_q->getQuery()->getSingleResult();
但我总是得到:
SQLSTATE[42000]:语法错误或访问冲突:1064 您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在第 1 行的“Usage u0_ WHERE u0_.var = 'warranty'' 附近使用正确的语法
这是我的使用实体:
<?php
namespace Herbanist\AdminBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* Usage
*
* @ORM\Table()
* @ORM\Entity
*/
class Usage
{
/**
* @var integer
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="var", type="string", length=20)
*/
private $var;
/**
* @var string
*
* @ORM\Column(name="value", type="text")
*/
private $value;
public function getId()
{
return $this->id;
}
public function setVar($var)
{
$this->var = $var;
return $this;
}
public function getVar()
{
return $this->var;
}
public function setValue($value)
{
$this->value = $value;
return $this;
}
public function getValue()
{
return $this->value;
}
}
使用表:
mysql> select * from `Usage`;
+----+----------+-------+
| id | var | value |
+----+----------+-------+
| 1 | warranty | 0 |
+----+----------+-------+