14

DoctrineDQLクエリの実行に問題があります。これは私に与えるエラーです。

Doctrine\Common\Annotations\AnnotationException: [Syntax Error] Expected PlainValue, 
got 'integer' at position 13 in property Base\Session::$lifetime.

私のコードは次のようになります:

$query = $em->createQuery("SELECT s FROM Base\Session s WHERE s.session = \"$id\"");

ここで、$idは現在のsession_idです。私のモデルは次のようになります:

namespace Base;

/** @Entity @Table(name="session") */
class Session extends Skeleton {
/**
 * @Id @Column(type="integer")
 * @GeneratedValue(strategy="AUTO")
 */
protected $id;

/** @Column(length=32) */
protected $session;

/** @Column(type=integer) */
protected $lifetime;

/** @Column(type=integer) */
protected $modified;

/** @Column(type="text") */ 
protected $data;
}
4

1 に答える 1

26

これには2つのエラーがあります。

  1. 注釈を二重引用符で囲む必要があります。つまり、で@Column(type="integer")はありません@Column(type=integer)。マッピングが間違っていると、Doctrine \ Common \ Annotations\AnnotationExceptionがスローされます。これはクエリとは何の関係もありません。

  2. クエリでは、プリペアドステートメントを使用する必要があります。

    $query = $em->createQuery("SELECT s FROM Base\Session s WHERE s.session = ?1"); $query->setParameter(1, $id);

于 2010-08-17T14:47:58.593 に答える