Mysql method to set the conditions for auto-increment id: 1. Set the id field as the primary key when creating the data table; 2. Use the "alter table table name modify id int(11) auto_increment;" statement as the id field Just add the auto_increment attribute.
When the PHP file executes the MySQL database insert statement, it is often necessary to execute the id auto-increment attribute. Otherwise, 0 will always be returned when the mysqli_insert_id function is executed.
If you want to implement id auto-increment, you need to set id as the primary key when creating the data table and set it to AUTO_INCREMENT.
Use SQL statements to set auto-increment for existing primary key fields
Step 1: Add the auto_increment attribute to id
alter table tablename modify id int(11) auto_increment;
Step 2: Set the initial value for the self-increasing value
alter table tablename auto_increment=10000;
More related free learning recommendations: mysql tutorial(video)
The above is the detailed content of How to set the conditions for auto-incrementing id in mysql?. For more information, please follow other related articles on the PHP Chinese website!