使用doctrine添加新字段时显示PDO异常错误

时间:2014-02-21 04:49:09

标签: php sql zend-framework doctrine-orm

这是我的代码的一部分。当我第一次创建字段员工时     并键入...它完美地工作...但我试图添加第三个字段     它显示此错误。请帮助我找到错误

    ----------

显示原则错误

      [Doctrine\DBAL\DBALException]                                                
      An exception occurred while executing 'ALTER TABLE leave ADD days VARCHAR(1  
      00) NOT NULL':                                                               

      SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error i  
      n your SQL syntax; check the manual that corresponds to your MySQL server v  
      ersion for the right syntax to use near 'leave ADD days VARCHAR(100) NOT NU  
      LL' at line 1                                                                






      [PDOException]                                                               
      SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error i  
      n your SQL syntax; check the manual that corresponds to your MySQL server v  
      ersion for the right syntax to use near 'leave ADD days VARCHAR(100) NOT NU  
      LL' at line 1                                                               

    ----------

这是我的Model.Leave.php

    <?php

    namespace Application\Model;

    use Doctrine\ORM\Mapping as ORM;
    use Doctrine\Common\Collections\ArrayCollection;

    /**
     * @ORM\Table(name="leave")
     * @ORM\Entity
     */
    class Leave extends Entity
    {
        /**
         * @ORM\Column(type="string", length=100)
         * @var string
         */
        protected $employee;


        public function getEmployee()
        {
            return $this->employee;
        }

        public function setEmployee($emp)
        {
            $this->employee = $emp;
        }

        /**
         * @ORM\Column(type="string", length=100)
         * @var string
         */
        protected $type;


        public function getType()
        {
            return $this->type;
        }

        public function setType($type)
        {
            $this->type = $type;
        }

        /**
         * @ORM\Column(type="string", length=100)
         * @var string
         */
        protected $days;


        public function getDays()
        {
            return $this->days;
        }

        public function setDays($days)
        {
            $this->days = $days;
        }

    }

1 个答案:

答案 0 :(得分:0)

请参阅http://doctrine-orm.readthedocs.org/en/latest/reference/basic-mapping.html#quoting-reserved-words

您需要引用保留字,例如

/**
 * @ORM\Table(name="`leave`")
 * @ORM\Entity
 */