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.