Today, PHP is used in the project to update databases in batches. In fact, we should write the stored procedure, but we do not want to discard PHP. So after a Google review, we found that the multi_query function can be used to implement the fight operation function, I will briefly describe my ideas and add code. When you look at it, you can also give some suggestions to optimize the Code. In the future, my code will be shared open-source, so that everyone can learn it together. If not, gogogo needs: update a field in the database in batches. Assume It is a random field and update it with a randomly generated 6-Bit String (the algorithm used to generate a random string depends on my previous blog article)
Example: I first run the code to analyze how to operate
For ($ I = 1; $ I <= $ this-> size; $ I ++) {$ Query [] = "Update tb_enterprise set eid = '$ eidex [$ I]' Where eid = $ I" ;}$ QUERY_STRING = implode (";", $ query); $ query_result = $ db-> multi_query ($ query); if ($ query_result) {echo "successed to update data! ";} Else {echo" failed to update data! ";}