Codeigniter:我可以将数组传递给$ ci-> db-> select()吗?

时间:2018-09-30 10:13:15

标签: php codeigniter

我是CodeIgniter的新手,并试图找到将变​​量参数传递给$ci->db->select()的最佳方法

有时候我需要一个字段,有时需要3个字段,但是我想要一个函数。这是我的get函数:

function db_get($table, $what, $where) {
    $this->db->where($where);
    if( $what ) {
        $this->db->select($what);
    }
    return $this->db->get($table)->row_array();
}

我可以这样称呼吗?

$table = 'table_name';
$what = array('field_1', 'field_2');
$where = array('field_3' => 'value');

$result = $ci->import_db->db_get($table, $what, $where);

还是我需要先将其内爆?喜欢:

$what = implode(",", $what);

0 个答案:

没有答案