FAQ  |  Search  |  Register  |  Profile  |  Log in to check your private messages  |  Log in

MySQL Incremented Key

 
Post new topic   Reply to topic    Aprelium Forum Index -> Databases
View previous topic :: View next topic  
Author Message
Toasty
-


Joined: 21 Feb 2008
Posts: 287
Location: Chicago, IL

PostPosted: Mon Mar 30, 2009 4:30 pm    Post subject: MySQL Incremented Key Reply with quote

Hello.

I can't seem to figure out a way to do this, while looking around online:

Say if I just inserted a row into a database with PHP:

Code:
INSERT INTO database.table (`unique`, `othervar1`, `othervar2`) VALUES (NULL, 'var1', 'var2');


How would I find out right after the transaction occured what value MySQL put into the "unique" variable? Any help would be appreciated!

Thanks,
Toasty
_________________
Portfolio: Robert Lerner
Back to top
View user's profile Send private message Visit poster's website
pkSML
-


Joined: 29 May 2006
Posts: 862
Location: Bucyrus, Ohio

PostPosted: Mon Mar 30, 2009 5:06 pm    Post subject: Reply with quote

Is 'unique' set to auto-increment in your table setup? If so, then after the insert command is finished, you can use mysql_insert_id.
_________________
Stephen
Need a LitlURL?


My PBA sites | http://CodeBin.yi.org | http://Abyss-Websites.com
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
Toasty
-


Joined: 21 Feb 2008
Posts: 287
Location: Chicago, IL

PostPosted: Mon Mar 30, 2009 5:10 pm    Post subject: Reply with quote

It is. I'll look up that command.

Thanks for the quick response!
_________________
Portfolio: Robert Lerner
Back to top
View user's profile Send private message Visit poster's website
Toasty
-


Joined: 21 Feb 2008
Posts: 287
Location: Chicago, IL

PostPosted: Mon Mar 30, 2009 6:08 pm    Post subject: Reply with quote

That did exactly what I needed it too!

Thanks!

Link to php.net's mysql_insert_id page
_________________
Portfolio: Robert Lerner
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Aprelium Forum Index -> Databases All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB phpBB Group