在Doctrine中使用DQL(ORM工具)

I have a problem in working with dql in Doctrine 2 (I am working a project which Doctrine integrated with Zend Framework)

When I work with entity manager, following code successfully run

  $user= $this->_em->find('Core\Entities\Userlog', 1); //index=1
  $user->setlogindate(date(DATE_RFC822));
  $this->_em->persist($user);
  $this->_em->flush();

I need to run following code:

  $qb=$this->_em->createQueryBuilder();
  $qb->update("Core\Entities\Userlog",'t');
  $qb->where('t.userlog_id = 1');
  $qb->set('t.logindate',date(DATE_RFC822));
  $qb->getQuery()->execute();

but doctrine has a problem to handle this code. Any Idea?

Thanks in advance.

I believe the problem is that DQL cannot "magically" convert the RFC822 date to a DATETIME value matching Userlog::logindate field, like - I assume - it is happening in Userlog::setlogindate().

You should try using a date format compatible with your database engine, typically a 'Y-m-d H:i:s' format instead:

...
$qb->set('t.logindate', date('Y-m-d H:i:s'));
...