can any one help me to use the mysql inbuilt function in cakePHP?????
2 Answers
If you don't want to use
$this->Model->query($yoursql);
Then there's still another way for some mysql functions such as concat,date_format
$this->Model->find($findtype,array('fields'=>array('concat (column1,column2,...) as con','date_format(...) as mydate'),'conditions'=>...));
2 Comments
RSK
why this statement
$competition = $this->Competition->find('first', 'fields' => array('(fee1+fee2) AS total','id','title' ))); results $competition=array(0=>array('total' => 8),'Competition' => array('id' => 1,'title' => 'Competition1'));Young
@RSK,that's right.If you don't like this style,see nuts-and-bolts-of-cakephp.com/2008/09/29/…
There is an example of how to use CONCAT in the book. I imagine you would be able to extend the syntax to use the other MySql functions as required.
1 Comment
Leo
The use of virtual fields is documented in the manual: book.cakephp.org/view/1608/Virtual-fields. They only appeared with version 1.3, however. I would probably opt for the $this->Model->query($yoursql); construct in this case - that's what it's there for.
$this->Model->query()