<?php
// Includo
require_once(dirname(__FILE__) . '/../inc.php');
require_once(dirname(__FILE__) . '/admin.php');
$xml = simplexml_load_file('michele.xml');
$tables = array('news','photo','pagine');
function OttieniDati($insert){
global $db,$query;
foreach($insert as $key => $value)
if(!is_array($value))
$query .= $db->real_escape_string($key)."='".$db->real_escape_string($value).(end($insert)==$value?'\'':'\',');
}
foreach($tables as $table){
$current_array = json_decode(json_encode($xml->{'table_'.$table}),true);
$id = '';
foreach($current_array[$table] as $insert){
$query = "INSERT INTO ".$table." SET ";
if(isset($insert['id'])){
if($insert['id']==$id) continue;
$id = $insert['id'];
}
OttieniDati(is_array($insert) ? $insert : $current_array[$table]);
if($query!="INSERT INTO ".$table." SET ")
$db->query($query) or die('Errore nella query: '.$query.' '.$db->error);
if(!is_array($insert)) break;
}
}
?>