I have several text files that I need to open, then allocate some fields to set string in PHP So that MySQL can finally write
Each textile file has the same unique value for the app_id, such as
then text file 1
details of the API name
In the text file 2
The APDID category
The text file is 3
APIID
Let me name, Get the category
$ fp = fopen ('textfile1', 'r') and the value for each record, and write that in mysql. ); If (! $ Fp) {echo 'error: unable to open file & Lt; / Table & gt; & Lt; / Body & gt; & Lt; / Html & gt; '; Exiting;} while ((FIF ($ fp)) {$ line = stream_get_line ($ fp, 4096, $ eoldelimiter); If ($ line [0] === '#') will continue; Skip the lines starting with the $ # $ $ [$ loop] = explosion ($ delimiter, $ line); List ($ app_id, $ name, $ description) = explosion ($ delimiter, $ line); $ Fp ++; } Fclose ($ fp); ? & Gt;
My question is how to read the second and third files? Can I somehow do it in parallel, or I need to complete the text file 1, write each line in mysql and then open the text file 2 and replace it in the app_id key, write the range in my SQL, then the text file 3
I would recommend the following approach:
- < Li>
- Make an empty array that is used with an APID sequence
- Simple class with the following class: Name, description, category, and value
-
Read each file and The result is affected for the right element in the array
if (! Isset ($ array [$ app_id])) $ Sir [$ app_id] = New MyClass ();array [$ app_id] - & gt; Name = $ name;array [$ app_id] - & gt; Details = $ description; -
Once you read all the files, you can repeat through the array and write each table in the SQL table.
Comments
Post a Comment