CakePHP Save update and find queries

1) Save single form data to single table in your database.

$this->Model->save($this->data);

2) Save single form data to single table with conditions(where clause)

$this->Model->save(array(‘Model.field1’=>$f1,’Model.field2’=>$f2,’Model.field3’=>$f3),array(‘Model.id’=>$id));

3)Update single table

$this->Model->update(array(‘Model.field1’=>$f1,’Model.field2’=>$f2,’Model.field3’=>$f3),array(‘Model.id’=>$id));

4)Find data from single table

$this->Model->find(‘all’);  //finds all details

$this->Model->find(‘first’);  //finds first detail

$this->Model->find(‘all’,array(‘Model.id’=>$id)); //finds the records having id=$id

$this->Model->find(‘all’,array(‘Model.id’=>$id,’Model.status’=>1)); //finds the records having id=$id and status field value 1

$this->Model->findById($id);//finds single field whose id field value is $id(Use name of field at place of ‘Id’ written in findById)

 

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s