【问题标题】:use mysql inbuilt functions with cakePHP find()将 mysql 内置函数与 cakePHP find() 一起使用
【发布时间】:2010-07-15 09:05:07
【问题描述】:

谁能帮我使用cakePHP中的mysql内置函数??????

【问题讨论】:

  • PHP内置的还是Cake内置的?
  • 我提到了内置的mysql数据库函数,如DATE_FORMAT(),CONCAT(string1,string2,...),REPLACE(whole_string,to_be_replaced,replacement)...... ...keithjbrown.co.uk/vworks/mysql/mysql_p9.php
  • 您可以随时避开框架并使用$this->Model->query()
  • 有,就像 SpawnCxy 的回答一样!

标签: mysql cakephp cakephp-1.3


【解决方案1】:

如果你不想使用

$this->Model->query($yoursql);

那么对于一些mysql函数如concat,date_format还有另一种方式

$this->Model->find($findtype,array('fields'=>array('concat (column1,column2,...) as con','date_format(...) as mydate'),'conditions'=>...));

【讨论】:

  • 为什么这个声明$competition = $this->Competition->find('first', 'fields' => array('(fee1+fee2) AS total','id','title' )));结果$competition=array(0=>array('total' => 8),'Competition' => array('id' => 1,'title' => 'Competition1'));
  • @RSK,没错。如果您不喜欢这种风格,请参阅nuts-and-bolts-of-cakephp.com/2008/09/29/…
【解决方案2】:

book 中有一个如何使用 CONCAT 的示例。我想您可以根据需要扩展语法以使用其他 MySql 函数。

【讨论】:

  • 手册中记录了虚拟字段的使用:book.cakephp.org/view/1608/Virtual-fields。然而,它们只出现在 1.3 版中。我可能会选择 $this->Model->query($yoursql);在这种情况下构造 - 这就是它的用途。
猜你喜欢
  • 1970-01-01
  • 2018-07-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-08-20
相关资源
最近更新 更多