Page 1 of 1

Synchronous MySQL: return row ID on INSERT query?

Posted: Fri Dec 12, 2008 5:15 am
by JAB Creations
I'm curious if MySQL has any synchronous option that would return values on an INSERT query?

Such a return would negate the need to execute a SELECT query to get the ID of the newly created row. For example when creating a new forum thread there is the need to create a row in the thread table and then create a row in the post table. I need to get the newly created ID of the thread so I can associate the row I'll INSERT next in to the posts table to the thread.

I can do the old fashioned method just fine though it'd be nice if this sort of approach exists. :mrgreen:

Re: Synchronous MySQL: return row ID on INSERT query?

Posted: Fri Dec 12, 2008 6:08 am
by novice4eva
I know that it can be done via procedure using IN/OUT in paramter list but i dunno if there is a straight way to get one out of insert sql!!

Re: Synchronous MySQL: return row ID on INSERT query?

Posted: Fri Dec 12, 2008 7:15 am
by Eran

Re: Synchronous MySQL: return row ID on INSERT query?

Posted: Fri Dec 12, 2008 10:01 pm
by JAB Creations
I thought I had replied earlier today! Any way thanks! This saves me from having to make an unnecessary MySQL query! :mrgreen: How come when I randomly read php.net I don't find anything useful? :|