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

有帮助吗?

解决方案 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.

其他提示

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)))
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top