【发布时间】:2013-05-07 04:33:35
【问题描述】:
我正在使用一个函数来设置整个 sql 查询。 其他两个使用这个函数来获取sql,然后根据需要使用它。
现在,我想要另一个函数来执行相同的查询,但我不需要之前的函数需要的所有字段。所以,我想知道是否有办法在设置后替换查询的 SELECT 部分。
伪代码:
function sql(){
$this->db->select('*');
$this->db->from('table');
}
function defaultSql(){
$this->sql();
$this->get();
}
function notAllFields(){
$this->sql();
// This is the solution I'm looking for. It should clear the select
$this->db->clearSelect();
// I define a different select
$this->db->select('field');
$this->get();
}
提前致谢!
【问题讨论】:
-
请注意,我正在寻找一个实际上清除已设置的选择的解决方案。我的源代码比示例复杂得多,所以我不想将任何参数传递给 sql 函数。 ;)
标签: php mysql codeigniter select