14

I'm having trouble executing a Doctrine DQL Query. This is the error it gives me.

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

My code looks like this:

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

Where $id is the current session_id. My Model looks like:

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;
}
Rene Terstegen
  • 7,911
  • 18
  • 52
  • 74

1 Answers1

27

You have two errors in this:

  1. You have to double quote your annotations, i.e. @Column(type="integer") not @Column(type=integer). Doctrine\Common\Annotations\AnnotationException is thrown when your mapping is wrong. This has nothing to do with the query.

  2. Your query should use prepared statements, i.e.

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

Evan Donovan
  • 748
  • 9
  • 18
beberlei
  • 4,297
  • 1
  • 23
  • 25
  • Thanks. The first error was the solution. I already knew your second point. Just tried so many things I ended up with this line of code in which I forgot to use the prepared statement. Thanks a lot! – Rene Terstegen Aug 18 '10 at 09:22
  • 5
    As an additional comment to #1, single quotes do not work either, must be double quotes – Shawn Sep 05 '13 at 15:24