-1

For example, if the table desc is,

id int(11) pk auto_increment
content varchar(128)

and if i inserted (null, 'test') how can i get the inserted new id?

the input 'test' can't be the where condition, because it is not a unique key, it can be duplicated.

Any good idea?

or do i have to redesign the table to insert some unique key for that?

NDM
  • 6,731
  • 3
  • 39
  • 52
user1765884
  • 105
  • 1
  • 4
  • 13

3 Answers3

1

Try with $this->db->insert_id() like

$this->db->insert(); //Here your insert query
echo "Insert Id is ".$this->db->insert_id();

Try this LINK

GautamD31
  • 28,552
  • 10
  • 64
  • 85
0

You might be looking for LAST_INSERT_ID

LAST_INSERT_ID is a value representing the first automatically generated value that was set for an AUTO_INCREMENT column by the most recently executed INSERT statement to affect such a column. It is session specific.

Praveen Prasannan
  • 7,093
  • 10
  • 50
  • 70
0

If you want the last insert id, you can try this

$this->db->insert_id();
Eswara Reddy
  • 1,617
  • 1
  • 18
  • 28