Controlled Posted May 4, 2014 Share Posted May 4, 2014 I was wondering how I could get the mysql_insert_id to reset. For example, I have deleted the row that had the ID 1, and now it moves onto the ID 2, even though there isn't a row with ID 1 anymore. Is there anyway to reset this? Thanks https://wiki.multitheftauto.com/wiki/Mo ... _insert_id Link to comment
JR10 Posted May 5, 2014 Share Posted May 5, 2014 Try this local qh = dbQuery(db, 'SELECT LAST_INSERT_ID() AS id') local result = dbPoll(qh, -1) local id = result[1]['id'] You should never use dbPoll with -1 as it freezes the whole thing until it obtains the result, instead use callbacks. Link to comment
tosfera Posted May 5, 2014 Share Posted May 5, 2014 There are several ways to do this, you can also use MAX(). Another way you can do to make sure you get the last one ( if you don't trust MAX() or LAST_INSERT_ID() ) you can make a query that selects everything, or just the id and order it by ID, DESC ( descend ) and limit it with; limit 0,1. Another thing, mysql is a database, where your database is being stored. Quite an inception, and Database is being built by another database ( you can read all about it on the internet ). An auto_increment will never reset, the only actual way to do it is to set it yourself. You can either make it an int and make your own increment or select the last id and overwrite the empty id. Link to comment
Controlled Posted May 5, 2014 Author Share Posted May 5, 2014 Try this local qh = dbQuery(db, 'SELECT LAST_INSERT_ID() AS id') local result = dbPoll(qh, -1) local id = result[1]['id'] You should never use dbPoll with -1 as it freezes the whole thing until it obtains the result, instead use callbacks. If that should not be used then what is a better way to do it? There are several ways to do this, you can also use MAX(). Another way you can do to make sure you get the last one ( if you don't trust MAX() or LAST_INSERT_ID() ) you can make a query that selects everything, or just the id and order it by ID, DESC ( descend ) and limit it with; limit 0,1. Another thing, mysql is a database, where your database is being stored. Quite an inception, and Database is being built by another database ( you can read all about it on the internet ). An auto_increment will never reset, the only actual way to do it is to set it yourself. You can either make it an int and make your own increment or select the last id and overwrite the empty id. Sorry I did not follow. What is MAX() and how would it be used in a script? In your second paragraph I understand what you are saying, so I am asking for a alternative to it. Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now