CakePHP,从模型查询 [英] CakePHP, Query from Model
本文介绍了CakePHP,从模型查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在CakePHP中执行SQL查询。
How I can execute a SQL query in CakePHP.
我想编写类似这样的代码
I want to make some like this code
$employees = $this->Employee->find('all');
但引入了我自己的SQL语句。
but introducing my own SQL statment.
推荐答案
将执行SQL语句的函数插入模型中,
Insert into your Model a function that executes your SQL statment,
public function get_employees() {
$sql = 'select * from employees';
$data = $this->query($sql);
return $data;
}
按以下方式调用此函数:
And call this function like this way:
$employee = new Employee();
$data = $employee->get_employees();
这篇关于CakePHP,从模型查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文