This is my database config:-
$db['default'] = array(
'hostname' => 'localhost',
'username' => 'root',
'password' => '',
'database' => 'test_db',
'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => TRUE,
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE
);
I insert user using this and output last id on die();
$this->db->insert("user",$data);
$lastid=$this->db->insert_id();
die($lastid);`
It outputted 0
But when I use:-
$query = $this->db->query('SELECT LAST_INSERT_ID()');
$row = $query->row_array();
$lastid= $row['LAST_INSERT_ID()'];
die($lastid);
It outputted the last inserted id...
I have an auto_increment
on user_id
Why $this->db->insert_id()
wont work?