Jump to content

Import Data From Xml File To Database


bullex

Recommended Posts

I need a little help for a script theat makes a import in to a table from 2 xml files .

The probles is theat i could do the insert from the first xml file but when i try to import data from the second xml ( the update script) does not work.

 

 

<?php

 

error_reporting(E_ALL ^ E_NOTICE);

ini_set('display_errors', 1);

ini_set('max_execution_time', 999999999);

 

require_once('config.php');

require_once('functions.php');

require_once('class.GetProd.php');

 

$html = file_get_contents('xml/cezar5423.xml');

 

$GetProd = new GetProd();

$GetProd->parameters = array('TYPE', 'BRAND', 'TITLE', 'VOLUME', 'SEX', 'NOTE', 'SET', 'PICTURE', 'EAN', 'DAMAGED', 'TESTER');

$product = $GetProd->processing($html);

 

foreach ( $product as $product_id => $val ) {

 

$sefurl = sefurl($product[$product_id]['TITLE']);

 

if ( strlen($sefurl) > 0 ) {

 

$type = mysql_real_escape_string(trim($product[$product_id]['TYPE']));

$brand = mysql_real_escape_string(trim($product[$product_id]['BRAND']));

$title = mysql_real_escape_string(trim($product[$product_id]['TITLE']));

$volume = mysql_real_escape_string(trim($product[$product_id]['VOLUME']));

$sex = mysql_real_escape_string(trim($product[$product_id]['SEX']));

$note = mysql_real_escape_string(trim($product[$product_id]['NOTE']));

$set = mysql_real_escape_string(trim($product[$product_id]['SET']));

$ean = mysql_real_escape_string(trim($product[$product_id]['EAN']));

$damaged = mysql_real_escape_string(trim($product[$product_id]['DAMAGED']));

$tester = mysql_real_escape_string(trim($product[$product_id]['TESTER']));

$date = date('Y-m-d H:i:s', time());

 

if ( mysql_num_rows(mysql_query("SELECT * FROM `products` WHERE id='$product_id'")) < 1 ) {

mysql_query("INSERT INTO products (`id`, `sku`, `name`, `producer`, `type`, `volume`, `sex`, `note`, `set`, `damaged`, `tester`, `image`, `sefurl`, `created`) VALUES ('$product_id', '$ean', '$title', '$brand', '$type', '$volume', '$sex', '$note', '$set', '$damaged', '$tester', '$sefurl', '$sefurl', '$date')");

}

 

}

 

}

 

$html = file_get_contents('xml/cezar54233.xml');

$GetProd->parameters = array('PRICE', 'AVAILABILITY', 'STOCK');

$product = $GetProd->processing($html);

 

foreach ( $product as $product_id => $val ) {

$stock = $product[$product_id]['STOCK'];

$price = $product[$product_id]['PRICE'];

$published = ( $product[$product_id]['AVAILABILITY'] == 'in stock' ) ? 1 : 0;

mysql_query("UPDATE `products` SET stock='$stock', price='$price', published='$published' WHERE id='$product_id'");

}

 

?>DONE

Link to comment
https://forums.phpfreaks.com/topic/271896-import-data-from-xml-file-to-database/
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.