CI框架开发散记

添加:

public function insert_code_relation($data) {
    $this->db->insert('code_relation', $data);
    return $this->db->insert_id();
}
修改:
public function update_code($code, $data, $field = 'code') {
    $this->db->where($field, $code);
    $this->db->update('code', $data);
    return $this->db->affected_rows() > 0;
}

获取数据:

public function get_code_relation($code, $target_id, $code_type) {
    $query = $this->db->where(array('code' => $code, 'code_type' => $code_type, 'target_id' => $target_id))->get('code');
    return $query->row_array();
}

删除:

public function delete_code_relation($keyword, $field = 'code') {
    $this->db->where(array($field => $keyword));
    $this->db->delete('code_relation');
}

 

查询:

// 计算总数
if (isset($params['where']) && $params['where']) {
    $this->db->where($params['where']);
}
if (isset($params['like']) && $params['like']) {
    $this->db->like($params['like']);
}
$total = $this->db->count_all_results('code_batch');
return array('total' => $total, 'limit' => $params['limit'], 'list' => $result ? $result : null);

你可能感兴趣的:(业余)