PHP How to import TXT file and batch update MySQL database

Source: Internet
Author: User
My TXT file data.txt format is as follows, separated by | Two fields, one is the device number, and the other is the state
A201| is being maintained.
A202| has been completed.
A203| is being maintained.
b201| equipment has been broken, waiting for processing
。。。
Now you want to batch update MySQL database with PHP, each device number is executed
Update Shebei set content= ' TXT file in the second field ' where shebeiid= ' txt file in the first field '
How do I write this PHP code? Beginner, need code

Excel table format I will use Excel_reader, but now people give me the file format is txt, because I touch the code is not much, do not know how to get


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 to execute SQL instructions
}

Master Upstairs, thank you.

Look at the ... Use the

This is really too simple.

  • 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.