0

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

4
  • Which ones, the ones built into PHP or those built into Cake? Commented Jul 15, 2010 at 9:06
  • i mentioned about the inbuilt mysql database functions such as DATE_FORMAT(),CONCAT(string1,string2,...),REPLACE(whole_string,to_be_replaced,replacement)............ keithjbrown.co.uk/vworks/mysql/mysql_p9.php Commented Jul 15, 2010 at 9:12
  • You can always sidestep the framework and use $this->Model->query() Commented Jul 15, 2010 at 9:24
  • There is, as in SpawnCxy's answer! Commented Jul 15, 2010 at 10:38

2 Answers 2

3

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'=>...));
Sign up to request clarification or add additional context in comments.

2 Comments

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,that's right.If you don't like this style,see nuts-and-bolts-of-cakephp.com/2008/09/29/…
0

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

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.