Welcome Guest, Not a member yet? Register   Sign In
getting last insert id
#1

[eluser]Unknown[/eluser]
I am using $this->db->query() function to execute insert query(classical style).At this time if i am using $this->db->insert_id() function to retrive last insert id.But that function always returns 0 instead of last insert id.I am using mysql db.So please guide me or provide function to get last insert id with classical style.
#2

[eluser]Dam1an[/eluser]
You can use the MySQL function mysql_insert_id()
#3

[eluser]Michael Wales[/eluser]
CodeIgniter also has the very helpful $this->db->insert_id();
#4

[eluser]Dam1an[/eluser]
@Michael: Tut tut tut, didn't read the thread properly

[quote author="ganno" date="1241977518"]At this time if i am using $this->db->insert_id() function to retrive last insert id.But that function always returns 0 instead of last insert id.[/quote]

(Sorry, had to be said Tongue)
#5

[eluser]Michael Wales[/eluser]
Whoops - nice catch! I am curious as to why the function is returning 0 everytime...
#6

[eluser]Dam1an[/eluser]
Without ooking at its implementation, these are onlky guesses
- There is no auto incrementing ID
- Its a multipart primary key (but this function can only return a single value)
- There may be more then one unique fields in the table

@Ganno: Does this happen with all your tables, or just one? Whats the schema for your table?




Theme © iAndrew 2016 - Forum software by © MyBB