我认为使用ci的活动记录来编译查询实际上是一个更好的主意。
一个例子:
function all_clients($select)
{
$this->db->select($select);
return $this->_get_client_data();
}
function single_client($select, $id = "")
{
// validate $id
$this->db->select($select);
$this->db->where("id", $id);
$this->db->limit(1);
return $this->_get_client_data();
}
// Only called by a method above once the query parameters have been set.
private function _get_client_data()
{
$q = $this->db->get("clients");
if($q->num_rows() > 0)
{
return $q->result_array();
}
return FALSE;
}
ci的活跃记录让你想做的事情变得简单多了。可以想象在实际调用之前设置公共函数来有条件地设置许多选项
$this->db->get()
.
我想你会打电话
_get_client_data
一网打尽(?)通过一个方法运行所有的数据检索,使得错误处理这样的事情更容易维护。
注意:永远记住这样验证数据。我知道你知道,但我只是重复。