Symfony 3.4新实体:语法错误或访问冲突

时间:2018-10-24 13:01:52

标签: php mysql symfony

大家好,我在创建新的“对话”实体时遇到错误,我真的看不出错误在哪里:/我有这个问题:

  

在执行带有参数[0、8、8、9]的“ INSERT INTO对话(读,last_send,id_user_one,id_user_two)VALUES(?,?,?,?)”时发生异常:   SQLSTATE [42000]:语法错误或访问冲突:1064 SQL语法有错误;在第1行的'read,last_send,id_user_one,id_user_two)VALUES(0,8,8,9)'附近检查与您的MySQL服务器版本相对应的手册以使用正确的语法

我的实体:

/**
 * @var integer
 *
 * @ORM\Column(name="id", type="integer", nullable=false)
 * @ORM\Id()
 * @ORM\GeneratedValue(strategy="IDENTITY")
 */
protected $id;

/**
 * @var \AppBundle\Entity\User
 *
 * @ORM\GeneratedValue(strategy="NONE")
 * @ORM\ManyToOne(targetEntity="User")
 * @ORM\JoinColumns({
 *   @ORM\JoinColumn(name="id_user_one", referencedColumnName="id")
 * })
 */
protected $id_user_one;

/**
 * @var \AppBundle\Entity\User
 *
 * @ORM\GeneratedValue(strategy="NONE")
 * @ORM\ManyToOne(targetEntity="User")
 * @ORM\JoinColumns({
 *   @ORM\JoinColumn(name="id_user_two", referencedColumnName="id")
 * })
 */
protected $id_user_two;

/**
 * @var int
 *
 * @ORM\Column(name="read", type="integer")
 */
protected $read;

/**
 * @var int
 *
 * @ORM\Column(name="last_send", type="integer")
 */
protected $last_send;

我的控制器:

$em = $this->getDoctrine()->getManager();

$user = $em->getRepository(User::class)->findOneBy(array('id' => ($request->get('id_user'))));
$friend = $em->getRepository(User::class)->findOneBy(array('id' => ($request->get('id_friend'))));

$new_conv = new Conversation();
$new_conv->setLastSend($user->getId());
$new_conv->setRead(0);
$new_conv->setIdUserOne($user);
$new_conv->setIdUserTwo($friend);
$em->persist($new_conv);
$em->flush();

0 个答案:

没有答案