Synchronous MySQL: return row ID on INSERT query?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Synchronous MySQL: return row ID on INSERT query?

Post 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:
User avatar
novice4eva
Forum Contributor
Posts: 327
Joined: Thu Mar 29, 2007 3:48 am
Location: Nepal

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

Post 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!!
User avatar
Eran
DevNet Master
Posts: 3549
Joined: Fri Jan 18, 2008 12:36 am
Location: Israel, ME

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

Post by Eran »

User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

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

Post 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? :|
Post Reply