반응형
원칙 오류: 구문 오류 또는 액세스 위반: 10649
저는 Product와 Manager의 두 가지 클래스가 있습니다.각 클래스의 코드는 다음과 같습니다(Product에는 관련 코드만 입력합니다).
제품 엔티티 코드:
<?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;
}
}
컨트롤러에는 Manager 엔티티와 제품을 만드는 기능이 있습니다.처음에는 Manager 개체를 만들고 나중에 이들을 링크하는 Product 개체를 만듭니다.그런데 어제부터 Manager 오브젝트를 삽입하려고 할 때 보이지 않는 문제가 있습니다.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
누군가 도와주면 정말 고맙겠다.왜냐하면 나는 정말 이 문제에 얽매여 있기 때문이다.감사합니다!
where
는 예약어입니다.열 이름을 따옴표로 묶거나 변경해야 합니다.다음을 시도해 보십시오(백틱에 주의).
/**
* @ORM\Column(name="`where`", type="string", length=255, nullable=true)
*/
protected $where;
언급URL : https://stackoverflow.com/questions/40923691/doctrine-error-syntax-error-or-access-violation-10649
반응형
'programing' 카테고리의 다른 글
이름, 성, 시에서 보낸 이메일 목록을 작성하려면 어떻게 해야 합니까? (0) | 2022.12.07 |
---|---|
Java에서 문자열 표시 너비 계산 (0) | 2022.12.07 |
"key = value;" 쌍의 문자열을 사전으로 변환하는 방법은 무엇입니까? (0) | 2022.12.07 |
외부 키에 기반한 SQL 제약 조건 검사 (0) | 2022.12.07 |
Javascript를 사용하여 jquery 로드 여부 확인 (0) | 2022.12.07 |