After reading through possible options here on Stackoverflow, I don’t see an answer for the exact case I’m considering…
CASE: I have a php system that auto-generates mysql-connected templates.
In order for the system to work, I need each generated template to have a unique 6-digit integer assigned upon it’s creation. Instead of messing with randomizers, etc…
A) could I simply create a table in the database called ‘pageid’, with int(11) / unique / autoincrement with starting value 100000, and then during the template creation process, simply perform an insert on this table, and then a ‘select last_insert_id()’ to pull the last value, which is then injected into the template as it’s created? (in otherwords, the table’s only function is to generate and spit back the last unique id).
B) if so, are there any issues I should be concerned about using this method? (aside from the fact that it means a limit of only 899,999 templates can be generated – which is not an issue in this case).
Any thoughts or better methods appreciated…
Yes:
Note that I am using
MEDIUMINT(6)as it requires 1 byte less storage thanINTand has a more appropriate display width for your needs.You could instead just have that column in your
templatestable, and have theidautomatically assigned whenever a new record is inserted.