php - Updating last DB entry with Symfony & Doctrine -


firstly please excuse more poor code, i'm relatively new php/symfony/doctrine.

what trying achieve below code follows, need update 'notification_id' field of last db entry. top half of code retrieving id of last db entry can refer second half of code add notification id (which comes in via post) db entry.

 $em = $this->getdoctrine()->getmanager();     $query = $em->createquery(         'select z.id         appbundle:zeususers z         order z.id desc');     $query->setmaxresults(1);     $id = $query->getsinglescalarresult();      $notificationid = $this->getrequest()->get("notification_id");      $query = $em->createquery(         'update appbundle:zeususers z         set z.notification_id = $notificationid         z.id = $id');     $query->execute();      $em->flush();      return new response("", 200, array("content-type"=>"text/html")); 

code updated above

this returning following error:

[syntax error] line 0, col 57: error: expected literal, got '$' (500 internal server error) 

it seems having issues referencing variables outside query, ideas?

how second query in native symfony instead of using query function am?

managed functioning following:

$em = $this->getdoctrine()->getmanager(); $query = $em->createquery(     'select z.id     appbundle:zeususers z     order z.id desc'); $query->setmaxresults(1); $id = $query->getsinglescalarresult();  $notification_id = $this->getrequest()->get("notification_id");  $query1 = $em->createquerybuilder(); $q = $query1->update('appbundle:zeususers', 'z')     ->set('z.notification_id', '?1')     ->where('z.id = ?2')     ->setparameter(1, $notification_id)     ->setparameter(2, $id)     ->getquery(); $p = $q->execute();  return new response("", 200, array("content-type"=>"text/html")); 

thank assisted me.


Comments

Popular posts from this blog

cakephp - simple blog with croogo -

How to group boxplot outliers in gnuplot -

bash - Performing variable substitution in a string -