【问题标题】:Doctrine 2 PlainValue expected学说 2 PlainValue 预期
【发布时间】:2010-08-17 07:14:31
【问题描述】:

我在执行 Doctrine DQL 查询时遇到问题。这是它给我的错误。

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;
}

【问题讨论】:

    标签: php doctrine doctrine-query


    【解决方案1】:

    你有两个错误:

    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);

    【讨论】:

    • 谢谢。第一个错误是解决方案。我已经知道你的第二点了。刚刚尝试了很多事情,我最终得到了这行代码,我忘记使用准备好的语句。非常感谢!
    • 作为对#1的附加注释,单引号也不起作用,必须是双引号
    猜你喜欢
    • 1970-01-01
    • 2011-12-13
    • 2014-08-13
    • 2012-03-11
    • 1970-01-01
    • 1970-01-01
    • 2013-07-31
    • 2012-01-23
    • 2012-08-01
    相关资源
    最近更新 更多