views:

67

answers:

2

can any one help me to use the mysql inbuilt function in cakePHP?????

A: 

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.

Leo
How can i add a virtual field on the fly ie., for a specific find only???
RSK
The use of virtual fields is documented in the manual: http://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.
Leo
+3  A: 

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'=>...));
SpawnCxy
@SpawnCxy : 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'));`
RSK
@RSK,that's right.If you don't like this style,see http://nuts-and-bolts-of-cakephp.com/2008/09/29/dealing-with-calculated-fields-in-cakephps-find/
SpawnCxy