How to retrieve an incremental variable as soon as it is ins

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
stubarny1
Forum Newbie
Posts: 5
Joined: Mon Aug 23, 2010 5:39 pm

How to retrieve an incremental variable as soon as it is ins

Post by stubarny1 »

Hello,

Please could someone tell me how to retrieve an incremental variable from MYSQL as soon as it is inserted? (i.e. before another variable can be inserted)

Many thanks.

Stu
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: How to retrieve an incremental variable as soon as it is

Post by social_experiment »

If you have an auto-increment column you can retrieve the last value (for said column) from an INSERT query by using mysql_insert_id()
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Post Reply