[thelist] MySQL generated id

Joe Crawford jcrawford at avencom.com
Thu Sep 20 13:50:39 CDT 2001

noah wrote:
> Apologies if this is a dumb question . . .
> When I insert a new record into a MySQL table (via PHP), I use MySQL's
> auto-increment to create a unique id number for that record. What I'd like
> to do is immediately have access to the id number in PHP. I could use a
> separate select statement, but since I don't know the unique id, I run the
> risk of returning multiple records, rather than just the one I just inserted.
> Is there anyway to immediately have access to the id number generated when
> the record is inserted?

I believe mysql_insert_id() is a php function to do what you want --
documentation here:

I'm not sure if there's a native mysql way to do what you want though.

	- Joe <http://artlung.com/>
...................  Joe Crawford \\ Web Design & Development
.....  mailto:jcrawford at avencom.com \\ http://www.avencom.com
.... San Diego \\ CA \\ USA \\ AVENCOM: Set Your Sites Higher

More information about the thelist mailing list