I have XML files ranging from 10Kb to 1.5Gb. They contain product information. (see sample XML file below.) I need to write the product information into a mySQL table using PHP without reading the whole XML file into an object and using a whole lot of system memory. I've researched this a bit and found that XMLReader might be the best way to go as it cursors through the XML eliminating the need to read the whole file into an object.
As you can see from the sample below, some of these product detail tags might be empty. A sample SQL statement would look something like this: INSERT INTO tblprod (SKU,NAME,DESC,LDESC,URL,C
AT,CATID,P
RICE,STOCK
,KEYW,BRAN
D) VALUES ($SKU,$NAME,$DESC,$LDESC,$
URL,$CAT,$
CATID,$PRI
CE,$STOCK,
$KEYW,$BRA
ND) WHERE StoreGUID = $StoreGUID
How do I go about writing each individual product's data into mySQL? Can anyone please help with some code and explain the process to me? This needs to happen as fast as possible, and without using excessive system memory.
SAMPLE XML: (shows the information for 2 products)
<?xml version="1.0" encoding="utf-8" standalone="yes" ?>
- <ROOT>
<StoreGUID>068e2904-6f91-4
364-bd4e-c
9351567fac
b</StoreGU
ID>
- <PRODUCT>
<ACTION>ADD</ACTION>
<SKU>NKFI01</SKU>
<NAME>OPTICAL MOUSE</NAME>
<DESC>This is a SHORT description.</DESC>
<LDESC>This is a LONG description.</LDESC>
<URL>
http://www.mymouse.com?productid=16273</U
RL>
<CAT>COMPUTERS|INPUT</CAT>
<CATID>364</CATID>
<PRICE>205</PRICE>
<STOCK>10</STOCK>
<KEYW>MOUSE|OPTICAL|COMPUT
ER</KEYW>
- <Attrib>
<BRAND>LOGITECH</BRAND>
</Attrib>
</PRODUCT>
- <PRODUCT>
<ACTION>ADD</ACTION>
<SKU>NKFI02</SKU>
<NAME>OPTICAL MOUSE2</NAME>
<DESC>This is a SHORT description2.</DESC>
<LDESC>This is a LONG description2.</LDESC>
<URL>
http://www.mymouse.com?productid=16274</U
RL>
<CAT>COMPUTERS|INPUT</CAT>
<CATID />
<PRICE>210</PRICE>
<STOCK>5</STOCK>
<KEYW />
- <Attrib />
</PRODUCT>
Start Free Trial