Jump to content

For Pros; How to import XML?


Rommeo

Recommended Posts

Hi,

I have two xml files, one has 750 products, and the other one has 900 products (including product informations, stock information, sizes and photos)

so shortly one product in xml file is like this;

product_name: x t-shirt
product_code: x-t-shirt-101 (Alphanumerical)
Stocks(loop):
+Small: 50
+Large:200
Photo1 : http://....../main.jpg
Photo2: http://....../2.jpg

And my tables are like this:

Product (product_id (numerical), product_code (alphanumerical), name)
Photos (product_id, id.. )
Stocks (product_id, id..)

(So that I need to insert one product in my db, and take the id, and insert the xml-photos-data with the correct product_id to photos table, same goes with the stocks table)

So I m thinking about the easiest and most healthy way to import this amount of data, and I need to update it daily or weekly (planning to do it by cron jobs for now).  I have found some solutions but since I have not done this before could not decide which is the most secure way. Need to add that I can have other xml files from different companies to import later on, so I think I should code for long term.

Thank you in advance for your help.

Link to comment
Share on other sites

Is this a one time load? If so does it matter? You could write a SQL file from the data then have MySQL read that in and do it all at once. You could then schedule it to be loaded into the database in background so your web page does not time out. Depending on your server I'm not sure inserting 900 records would really take that long but if it did you can increase the time out.

Link to comment
Share on other sites

34 minutes ago, gw1500se said:

Is this a one time load? If so does it matter? You could write a SQL file from the data then have MySQL read that in and do it all at once. You could then schedule it to be loaded into the database in background so your web page does not time out. Depending on your server I'm not sure inserting 900 records would really take that long but if it did you can increase the time out.

Well It's not actually 900, 

// So the loop is gonna be something like;

for( <"900 data") {
  $query1 = "insert a data of 900"
  $query2 = "select productid of data where = product_code" || "take the last inserted row".
          for(<"count of stock lets say 5")  
              $query insert productid,stock;
          for(<"count of photos lets say 6") 
            $query insert productid,photoname;
}                 
                 

Well, I thought about it but I wanna see if there is any better alternatives.. 
 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.