Doctrine 2 PlainValue previsto
-
29-09-2019 - |
Domanda
Ho problemi l'esecuzione di una dottrina DQL query. Questo è l'errore che mi dà.
Doctrine\Common\Annotations\AnnotationException: [Syntax Error] Expected PlainValue,
got 'integer' at position 13 in property Base\Session::$lifetime.
I miei sguardi codice come questo:
$query = $em->createQuery("SELECT s FROM Base\Session s WHERE s.session = \"$id\"");
Dove $ id è il session_id corrente. Il mio aspetto modello come:
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;
}
Soluzione
Hai due errori in questo:
-
è necessario fare doppio citare le annotazioni, vale a dire non
@Column(type="integer")
@Column(type=integer)
. Doctrine \ Common \ NOTE \ AnnotationException viene generata quando la mappatura è sbagliato. Questo non ha nulla a che fare con la query. -
La vostra query deve utilizzare le istruzioni preparate, cioè.
$query = $em->createQuery("SELECT s FROM Base\Session s WHERE s.session = ?1"); $query->setParameter(1, $id);
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow