4

このクエリで構文エラーが発生します。

protected function _getimsg($id)
{
    $imsgRepository = $this->getDoctrine( )->getRepository( 'DonePunctisBundle:Imsg' );
    $imsg = $imsgRepository->findOneBy(array('to' => $id, 'read' => 0 ));
    if($imsg) {
        $em = $this->getDoctrine()->getEntityManager();
        $imsg->setRead('1');

        $em->persist( $imsg );
        $em->flush( );

        return $imsg->getContent();
    } else {
        return '';
    }

}

imsg エンティティ

<?php

namespace Done\PunctisBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
 * Imsg
 *
 * @ORM\Table(name="imsg")
 * @ORM\Entity
 */
class Imsg
{
/**
 * @var integer
 *
 * @ORM\Column(name="id", type="integer")
 * @ORM\Id
 * @ORM\GeneratedValue(strategy="AUTO")
 */
private $id;

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

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

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

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

/**
 * Set To
 *
 * @param string $to
 * @return Page
 */
public function setTo($to)
{
    $this->to = $to;

    return $this;
}

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

/**
 * Set content
 *
 * @param string $content
 * @return Page
 */
public function setContent($content)
{
    $this->content = $content;

    return $this;
}

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

/**
 * Set read
 *
 * @param integer $read
 * @return Imsg
 */
public function setRead($read)
{
    $this->read = $read;

    return $this;
}

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

}

エラー出力

「UPDATE imsg SET read = ?」の実行中に例外が発生しました。WHERE id = ?' パラメータ {"1":"1","2":1}:

SQLSTATE[42000]: 構文エラーまたはアクセス違反: 1064 SQL 構文にエラーがあります。MySQL サーバーのバージョンに対応するマニュアルで、1 行目の near 'read = '1' WHERE id = 1' を使用する正しい構文を確認してください。

何か案は?

4

2 に答える 2

24

MySQL マニュアルから: http://dev.mysql.com/doc/refman/5.5/en/reserved-words.html -READは予約語です。そのため、構文エラーが発生していると思います。

Doctrine は自動的に列名を引用できます:

<?php
/** @Column(name="`number`", type="integer") */
private $number;

列の名前にバッククォートを追加します - http://docs.doctrine-project.org/en/latest/reference/basic-mapping.html#quoting-reserved-wordsから取得

于 2013-01-21T10:58:43.363 に答える
0

yamlを使用する場合、これを行うことができます

Number:
type: entity
table: `number `
于 2016-10-25T09:29:20.367 に答える