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: 298
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
_________________
Audit the secure configuration of your server headers!
Back to top View user's profile Send private message Visit poster's website
pkSML
-


Joined: 29 May 2006
Posts: 952
Location: Michigan, USA

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?


http://CodeBin.yi.org
Back to top View user's profile Send private message Visit poster's website
Toasty
-


Joined: 21 Feb 2008
Posts: 298
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!
_________________
Audit the secure configuration of your server headers!
Back to top View user's profile Send private message Visit poster's website
Toasty
-


Joined: 21 Feb 2008
Posts: 298
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
_________________
Audit the secure configuration of your server headers!
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