How does php import TXT files and update mysql databases in batches?

Source: Internet
Author: User
How does php import TXT files and batch update mysql database? the TXT file data.txt format is as follows: separate two fields with |: Device ID and status
A201 | in maintenance
A202 | completed
A203 | in maintenance
B201 | the device has crashed and is waiting for processing.
...
Now you want to use php to update mysql databases in batches. each device number is executed.
Update shebei set Content = 'second field in the TXT file 'Where shebeiID = 'first field in the TXT file'
How can I write this php code ?. Beginner, code required

I will use Excel_Reader to get the excel table format, but now the file format that someone else gave me is set to txt, because I don't have much access to code, I don't know how to get it.


Reply to discussion (solution)

$ Ar = array_map ('trim', file('data.txt '));
Foreach ($ ar as $ row ){
$ V = explode ('|', $ row );
$ SQL = "update shebei set Content = '$ v [1]' where shebeiID = '$ v [0]'";
// Code for executing SQL commands
}

Thank you!

Look... Used

It's really easy.

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.