2016-12-02 71 views
1

我有兩個類產品和經理,這裏是每一個類的代碼(在產品我都會把剛剛相關的代碼):主義錯誤:語法錯誤或訪問衝突:10649

代碼產品實體:

<?php 
namespace AppBundle\Entity; 

use Doctrine\ORM\Mapping as ORM; 
use Symfony\Component\Validator\Constraints as Assert; 


/** 
* @ORM\Table(name="products") 
* @ORM\Entity 
* @ORM\Entity(repositoryClass="AppBundle\Repository\ProductRepository") 
*/ 
class Product { 
    /** 
    * @ORM\ManyToMany(targetEntity="Manager", mappedBy="products") 
    **/ 
    private $manager; 
} 

這裏是進入我的控制器管理中心實體

<?php 
namespace AppBundle\Entity; 

use Doctrine\ORM\Mapping as ORM; 
use Symfony\Component\Validator\Constraints as Assert; 
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity; 


/** 
* @ORM\Table(name="shipping_methods") 
* @ORM\Entity 
*/ 
class Manager { 

    /** 
    * @ORM\Id 
    * @ORM\Column(type="integer") 
    * @ORM\GeneratedValue(strategy="AUTO") 
    */ 
    protected $id; 

    /** 
    * @ORM\Column(type="decimal", precision=8, scale=2, options={"default" = 0}) 
    */ 
    protected $percentage; 

    /** 
    * @ORM\Column(type="string", length=255, nullable=false) 
    */ 
    protected $name; 

    /** 
    * @ORM\Column(type="integer", nullable=false) 
    */ 
    protected $quantity; 

    /** 
    * @ORM\Column(type="string", length=255, nullable=true) 
    */ 
    protected $where; 

    /** 
    * @ORM\Column(type="string", length=255, nullable=true) 
    */ 
    protected $flag; 

    /** 
    * @ORM\ManyToMany(targetEntity="Product", inversedBy="shipping") 
    * @ORM\JoinTable(name="manager_methods") 
    **/ 
    protected $products; 

    /** 
    * Constructor 
    */ 
    public function __construct() 
    { 
     $this->products = new \Doctrine\Common\Collections\ArrayCollection(); 
    } 

    /** 
    * Get id 
    * 
    * @return integer 
    */ 
    public function getId() 
    { 
     return $this->id; 
    } 

    /** 
    * Set percentage 
    * 
    * @param string $percentage 
    * @return Manager 
    */ 
    public function setPercentage($percentage) 
    { 
     $this->percentage = $percentage; 

     return $this; 
    } 

    /** 
    * Get percentage 
    * 
    * @return string 
    */ 
    public function getPercentage() 
    { 
     return $this->percentage; 
    } 

    /** 
    * Set name 
    * 
    * @param string $name 
    * @return Manager 
    */ 
    public function setName($name) 
    { 
     $this->name = $name; 

     return $this; 
    } 

    /** 
    * Get name 
    * 
    * @return string 
    */ 
    public function getName() 
    { 
     return $this->name; 
    } 

    /** 
    * Set quantity 
    * 
    * @param integer $quantity 
    * @return Manager 
    */ 
    public function setQuantity($quantity) 
    { 
     $this->quantity = $quantity; 

     return $this; 
    } 

    /** 
    * Get quantity 
    * 
    * @return integer 
    */ 
    public function getQuantity() 
    { 
     return $this->quantity; 
    } 

    /** 
    * Set where 
    * 
    * @param string $where 
    * @return Manager 
    */ 
    public function setWhere($where) 
    { 
     $this->where = $where; 

     return $this; 
    } 

    /** 
    * Get where 
    * 
    * @return string 
    */ 
    public function getWhere() 
    { 
     return $this->where; 
    } 

    /** 
    * Set flag 
    * 
    * @param string $flag 
    * @return Manager 
    */ 
    public function setFlag($flag) 
    { 
     $this->flag = $flag; 

     return $this; 
    } 

    /** 
    * Get flag 
    * 
    * @return string 
    */ 
    public function getFlag() 
    { 
     return $this->flag; 
    } 

    /** 
    * Add products 
    * 
    * @param \AppBundle\Entity\Product $products 
    * @return Manager 
    */ 
    public function addProduct(\AppBundle\Entity\Product $products) 
    { 
     $this->products[] = $products; 

     return $this; 
    } 

    /** 
    * Remove products 
    * 
    * @param \AppBundle\Entity\Product $products 
    */ 
    public function removeProduct(\AppBundle\Entity\Product $products) 
    { 
     $this->products->removeElement($products); 
    } 

    /** 
    * Get products 
    * 
    * @return \Doctrine\Common\Collections\Collection 
    */ 
    public function getProducts() 
    { 
     return $this->products; 
    } 
} 

代碼我有哪裏我創建一個管理實體和產品的功能,首先我創建了一個管理對象,稍後我將創建一個Product對象來鏈接它們。但是有一個問題,自從昨天我嘗試插入管理器對象後,我就沒有看到它。我會在這裏粘貼給我Symfony的錯誤和我得到錯誤的代碼。

代碼,我得到錯誤:

$em = $this->getDoctrine()->getManager(); 
$shipping = new Manager(); 
$shipping->setPercentage(1); 
$shipping->setName("Name"); 
$shipping->setQuantity(1); 
$shipping->setFlag("flag"); 
$shipping->setWhere("where"); 
$em->persist($shipping); 
$em->flush(); 

這裏是來自Symfony的錯誤:

An exception occurred while executing 'INSERT INTO shipping_methods (percentage, name, quantity, where, flag) VALUES (?, ?, ?, ?, ?)' with params [1, "Name", 1, "where", "flag"]: 

SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'where, flag) VALUES ('1', 'Name', 1, 'where', 'flag')' at line 1 

如果有人能幫助我,我會非常非常感激由於我是真的卡住了這個問題...謝謝!

+0

請注意1064如何精確指向錯誤位置。 (有時,調皮的字/標點符號位於指定的位置之前;這一次是在該位置。) –

回答

2

where是保留字。您應該quote或重命名您的專欄。 試試這個(注意反引號):

/** 
* @ORM\Column(name="`where`", type="string", length=255, nullable=true) 
*/ 
protected $where; 
+0

我不知道...非常感謝你,你救了我更多的浪費時間...再次感謝 –