For Programmers: Free Programming Magazines  


Home > Archive > PHP Language > August 2005 > mysql autoincrement- return id









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author mysql autoincrement- return id

2005-08-28, 6:55 pm

Hello,
I have a table with column ID of auto increment type.
I want to insert a record in the table and then I want to show it's ID.
My best idea is to count the records in the table after inserting the
record.
But if 2 people will insert different records in the same time in the same
table, then
it is possible that they will get wrong ids.
To be sure that the script will always return right id I can write a sql
query that will search the table for record of values same as the ones, that
have been just saved.

But- can I do it easier and faster?

Regards,
Talthen


Jochem

2005-08-28, 6:55 pm

use mysql_insert_id() direct after your INSER Query.

More documentation on http://dk2.php.net/mysql_insert_id

Good luck!

Jochem

2005-08-28, 6:55 pm

User nicknamed <jdonkers@gmail.com> :
> use mysql_insert_id() direct after your INSER Query.


Thanks, that's *exactly* what I wanted :]

Regards,
Talthen


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com