开发者

How to read a bulk data feed via php?

I have a large file that I would like to read via php, and then insert various fields into MySQL.

Each file in the feed is in plain text format, separated into columns and rows. Each record has the same set of fields. The following are the delimit开发者_JS百科ers for each field and record:

Field Separator (FS): SOH (ASCII character 1) Record Separator (RS) : STX (ASCII character 2) + "\n"

If I look at the first few lines of the file they look like this:

#export_dateapplication_idlanguage_codetitledescriptionrelease_notescompany_urlsupport_urlscreenshot_url_1screenshot_url_2screenshot_url_3screenshot_url_4screenshot_width_height_1screenshot_width_height_2screenshot_width_height_3screenshot_width_height_4
#primaryKey:application_idlanguage_code
#dbTypes:BIGINTINTEGERVARCHAR(20)VARCHAR(1000)LONGTEXTLONGTEXTVARCHAR(1000)VARCHAR(1000)VARCHAR(1000)VARCHAR(1000)VARCHAR(1000)VARCHAR(1000)VARCHAR(20)VARCHAR(20)VARCHAR(20)VARCHAR(20)
#exportMode:FULL

I am struggling to no where to start in order to read this file into PHP, can anyone help with the basic PHP to read each record, and assign a variable to each field, which I then will be able to write into MySQL. I can handle the writing into SQL once I have the various fields set up.

Thanks in advance,

Greg


files greator than 2gb cant be read in PHP (32 bit limit).

For lower size use simple fopen function

And inserting mysql is all the work of macthing patterns and inserts.

If structure of table is same every row then better make it manual once and then just execute inserts by extracting values either by regex or other functions like explode and split .


If every line has delimiters between each field, you may look at fgetcsv().

When you use fgetcsv() on a line, it will return an array with the contents from that line. Since you have several lines, put the funciton inside a while()-loop (look at example #1)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜