Search code examples
phpmysqlcodeignitermysql-insert-id

If the column name of primary ,auto increment field is not id , can $this->db->insert_id() function be used


I am new to Codeigniter..

So this is my table:

request_id | login_name | login_password | reg_date | status

Can I use $this->db->insert_id() to get last inserted id if the primary auto increment column name is request_id instead of id?

Any help will be appreciated..


Solution

  • Yes, insert_id in MySQLi does not care about the column name, just that the column is AUTO_INCREMENT. It returns;

    The value of the AUTO_INCREMENT field that was updated by the previous query. Returns zero if there was no previous query on the connection or if the query did not update an AUTO_INCREMENT value.