Ошибка синтаксиса или нарушение прав доступа в Symfony и Doctrine

У меня ошибка Syntax error or access violation: 1064 Syntax error near 'read = '1' WHERE id = 1' at line 1

Вот мой метод действия контроллера:

    /**
     * @Route("/show/{id}", name = "pm_show", requirements = {"id" = "\d+"})
     */
    public function show(Request $request, $id)
    {
        $this->initialize();

        $user = $this->getUser();
        $repository = $this->getDoctrine()->getRepository(Pm::class);
        $messId = $id;
        $messageUser = $repository->findByMessId($messId);

        if ($messageUser[0]['read'] == 0)
        {
            $message = $repository->find($messageUser[0]['id']);
            if (!$message) {
                throw $this->createNotFoundException(
                    'No message found for id '.$messageUser[0]['id']
                );
            }
            /**********************************************/
            $message->setRead('1');
            $this->getDoctrine()->getManager()->flush();
            /**********************************************/
        }

        $this->addToTemplateArray(array (
            'mess_id' => $messId,
            'message' => $messageUser
        ));

        return $this->render('pm/pm_show.html.twig', $this->templateArray);
    }

И моя сущность:

<?php

namespace App\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * App\Entity\Pm
 *
 * @ORM\Table(name = "pm")
 * @ORM\Entity(repositoryClass = "App\Repository\PmRepository")
 */
class Pm
{
    /**
     * @var integer $id
     *
     * @ORM\Column(name = "id", type = "integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy = "AUTO")
     */
    private $id;

    /**
     *
     * @var App\Entity\User $sender
     *
     * @ORM\ManyToOne(targetEntity = "App\Entity\User")
     * @ORM\JoinColumn(name = "sender", referencedColumnName = "id")
     */
    private $sender;

    /**
     *
     * @var App\Entity\User $recipient
     *
     * @ORM\ManyToOne(targetEntity = "App\Entity\User")
     * @ORM\JoinColumn(name = "recipient", referencedColumnName = "id")
     */
    private $recipient;

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

    /**
     * @var text $content
     *
     * @ORM\Column(name = "content", type = "text")
     */
    private $content;

    /**
     * @var datetime $time
     *
     * @ORM\Column(name = "time", type = "datetime")
     */
    private $time;

    /**
     * @var string $read
     *
     * @ORM\Column(name = "read", type = "string", length=1)
     */
    private $read;


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

    /**
     * Set sender
     *
     * @param integer $sender
     */
    public function setSender($sender)
    {
        $this->sender = $sender;
    }

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

    /**
     * Set recipient
     *
     * @param integer $recipient
     */
    public function setRecipient($recipient)
    {
        $this->recipient = $recipient;
    }

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

    /**
     * Set title
     *
     * @param string $title
     */
    public function setTitle($title)
    {
        $this->title = $title;
    }

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

    /**
     * Set content
     *
     * @param text $content
     */
    public function setContent($content)
    {
        $this->content = $content;
    }

    /**
     * Get content
     *
     * @return text
     */
    public function getContent()
    {
        return $this->content;
    }

    /**
     * Set time
     *
     * @param datetime $time
     */
    public function setTime($time)
    {
        $this->time = $time;
    }

    /**
     * Get time
     *
     * @return datetime 
     */
    public function getTime()
    {
        return $this->time;
    }

    /**
     * Set read
     *
     * @param string $read
     */
    public function setRead($read)
    {
        $this->read = $read;
    }

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

Я не знаю, почему возникла эта ошибка. Я не вижу синтаксической ошибки, и я попытался обновить заголовок, например, моего объекта Pm, и он работает. Тогда проблема только в столбце чтения. Может, есть нарушение доступа, но я его не вижу. Я также пробовал обновлять вручную в базе данных, и это работает. Спасибо за помощь.

read - это зарезервированное слово mysql, а doctrine не ускользает от них.
u_mulder 25.09.2018 10:59

Тема для чтения stackoverflow.com/questions/10471234/…

u_mulder 25.09.2018 11:00

Doctrine не экранирует имена столбцов, если вы не сообщите об этом, по крайней мере, начиная с версии 2. См. github.com/doctrine/doctrine2/issues/5874

iainn 25.09.2018 11:00

Интересно, спасибо, ребята!

simslay 25.09.2018 11:10
Стоит ли изучать PHP в 2026-2027 годах?
Стоит ли изучать PHP в 2026-2027 годах?
Привет всем, сегодня я хочу высказать свои соображения по поводу вопроса, который я уже много раз получал в своем сообществе: "Стоит ли изучать PHP в...
Symfony Station Communiqué - 7 июля 2023 г
Symfony Station Communiqué - 7 июля 2023 г
Это коммюнике первоначально появилось на Symfony Station .
Оживление вашего приложения Laravel: Понимание режима обслуживания
Оживление вашего приложения Laravel: Понимание режима обслуживания
Здравствуйте, разработчики! В сегодняшней статье мы рассмотрим важный аспект управления приложениями, который часто упускается из виду в суете...
Установка и настройка Nginx и PHP на Ubuntu-сервере
Установка и настройка Nginx и PHP на Ubuntu-сервере
В этот раз я сделаю руководство по установке и настройке nginx и php на Ubuntu OS.
Коллекции в Laravel более простым способом
Коллекции в Laravel более простым способом
Привет, читатели, сегодня мы узнаем о коллекциях. В Laravel коллекции - это способ манипулировать массивами и играть с массивами данных. Благодаря...
Как установить PHP на Mac
Как установить PHP на Mac
PHP - это популярный язык программирования, который используется для разработки веб-приложений. Если вы используете Mac и хотите разрабатывать...
0
5
422
0

Другие вопросы по теме