store current auto increment value

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
greedyisg00d
Forum Commoner
Posts: 42
Joined: Thu Feb 12, 2009 2:48 am

store current auto increment value

Post by greedyisg00d »

I have a Student table and StudNo field which is set as primary key and auto increment is enabled. My problem is when I delete a specific row I noticed that the auto increment value remains the same. So is there a way to get the current auto increment value and store it to a variable? Sample code is much appreciated. Thanks
ocpaul20
Forum Newbie
Posts: 12
Joined: Thu Jul 05, 2007 3:53 am

Re: store current auto increment value

Post by ocpaul20 »

in mysql, I dont think an autoincrement field will decrement if you delete a record! It just keeps on incrementing. You will have to re-write the table to somewhere else if you need the autoincrement numbers to be sequential after you delete a record.
There is a mysql command to get the contents of the autoincrement field I believe. Although it might be a php mysql_ function I cannot remember, but I know I have seen it available.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: store current auto increment value

Post by requinix »

Whatever you want to do, don't. Not this way. An auto-increment field is the square peg solution to the round hole problem you have - find something else. Want advice: describe what you're trying to do.

(PS: ocpaul20 is probably thinking of mysql_insert_id but that does something slightly different.)
Post Reply