学说2 PlainValue预期
-
29-09-2019 - |
题
我在执行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;
}
解决方案
您有两个错误:
您必须加倍引用注释,即
@Column(type="integer")
不是@Column(type=integer)
. 。当映射错误时,将 common common entotation annotationException抛弃。这与查询无关。您的查询应使用已准备好的语句,即
$query = $em->createQuery("SELECT s FROM Base\Session s WHERE s.session = ?1"); $query->setParameter(1, $id);
不隶属于 StackOverflow