Welcome Guest, Not a member yet? Register   Sign In
how to get last insert id
#4

Try to ans, hopefully this solution can solve u're problem:

In CI-3, i do like this:
Field 'Id' => Primary Key and Auto Increment

Code:
//MODEL

function get_table(){
        $table = "tbl_name";
        return $table;
    }

function _insert($data){
        $table = $this->get_table();
        $this->db->insert($table, $data);
    }

function get_max(){
        $table = $this->get_table();
        $this->db->select_max('Id');
        $query = $this->db->get($table);
        return $query;
    }

//CONTROLLER

function bla(){
...
//INSERT NEW DATA:
$this->model_name->_insert($data);
$update_id = $this->model_name->get_max();
$this->resp_json['id'] = $update_id
...

}
Reply


Messages In This Thread
how to get last insert id - by imam - 12-25-2019, 02:50 AM
RE: how to get last insert id - by dannyweb - 12-25-2019, 06:09 PM
RE: how to get last insert id - by InsiteFX - 12-26-2019, 09:55 AM
RE: how to get last insert id - by imam - 12-27-2019, 12:08 AM
RE: how to get last insert id - by imam - 12-31-2019, 06:51 PM
RE: how to get last insert id - by maulahaz - 12-26-2019, 10:17 AM



Theme © iAndrew 2016 - Forum software by © MyBB