Skip to content

Instantly share code, notes, and snippets.

@necenzurat
Created July 3, 2013 19:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save necenzurat/5921918 to your computer and use it in GitHub Desktop.
Save necenzurat/5921918 to your computer and use it in GitHub Desktop.
<?php
/*
db connection shit loaded here
*/
set_time_limit(0);
ini_set('memory_limit', '120M');
include "XmlStreamer.php";
class SimpleXmlStreamer extends XmlStreamer {
public function processNode($xmlString, $elementName, $nodeIndex) {
static $int = 0;
$xml = simplexml_load_string($xmlString);
//var_dump($xml);
$title = mysql_real_escape_string($xml->title);
$description = mysql_real_escape_string($xml->description);
$link = mysql_real_escape_string($xml->aff_code);
$price = $xml->price;
$category = mysql_real_escape_string($xml->category);
$subcategory = mysql_real_escape_string($xml->subcategory);
$images = mysql_real_escape_string($xml->image_urls);
$brand = mysql_real_escape_string($xml->brand);
mysq_query("INSERT INTO `produse` (`id`, `title`, `description`, `brand`, `category`, `subcategory`, `price`, `images`, `link`, `view`, `click`)
VALUES ('', '$title', '$description', '$brand', '$category', '$subcategory', '$price', '$images', '$link', 0, 0);");
$int++;
echo chr(13)."importing... [".$int."]";
}
}
$streamer = new SimpleXmlStreamer("feed2parale.xml");
if ($streamer->parse()) {
echo "Finished successfully";
} else {
echo "Couldn't find root node";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment