PHP inserts a random code into the database based on the ID, and then judges that if the random code already exists in the database, it is randomly inserted into the database.
PHP inserts a random code into the database based on the ID, and then judges that if the random code already exists in the database, it is randomly inserted into the database.
Reply content:
PHP inserts a random code into the database based on the ID, and then judges that if the random code already exists in the database, it is randomly inserted into the database.
While (true) {// Generate a random number // Determine whether the database exists if ($ noFount) {// if not, // Insert the database break ;}}
The field defines the unique key. The transaction loop is inserted. the inserted commit is successful and the loop jumps out.
1. check the database code first.
2. then in_array () until false
3. Insert data