Question

in Cakephp if i have to update the record in some tables, i used update function

 $this->Userinfo->updateAll(
        array('number' => "'$number'"),
        array('User_id' => $userid)))

and the other way to update the record is to do this

i write query in my userinfo table in which i get the userid against the user.and then

   $this->Userinfo->id = $this->Userinfo->getUserid($userid);
   $this->Userinfo->save($data);

so now i want to ask what way is better .. do i have to use update or do i have to use save

Was it helpful?

Solution 2

If you're just saving one record, use the second version (save). UpdateAll is usually used when you're saving multiple records at the same time.

OTHER TIPS

That's totally depend on your requirement

Now if here you want to update just single record then go with

$this->Userinfo->id = $this->Userinfo->getUserid($userid);
$this->Userinfo->save($data);

And if you want to update more than one record in single query then go with

 $this->Userinfo->updateAll(
        array('number' => "'$number'"),
        array('User_id' => $userid)))
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top