PHP batch update database

Source: Internet
Author: User
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! ";}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.