<?php

//ini_set("memory_limit","1024M");
//set_time_limit(60000);

// get data
// connect import database

// old database
$connection=mysql_connect('localhost', 'root', '1234') or die ("Verbindungsversuch fehlgeschlagen");
mysql_select_db('intelectra', $connection) or die("Konnte die Datenbank nicht waehlen.1");

echo "get items<br>";
// get items
$query = mysql_query("
SELECT structure.id as sid , items.id as aid 
FROM import_item_structure_assign 
left join structure on import_item_structure_assign.rid = structure.old_id
left join items on import_item_structure_assign.pid = items.old_id
") or die("Anfrage nicht erfolgreich");
$data = array();
while($obj = mysql_fetch_object($query)) {
	$data[] = $obj;
}

// new database
$connection=mysql_connect('localhost', 'root', '1234') or die ("Verbindungsversuch fehlgeschlagen");
mysql_select_db('intelectra', $connection) or die("Konnte die Datenbank nicht waehlen.2");
echo "imports<br>";
foreach ($data as $object) {
	
		$sql = "
			INSERT INTO item_structure_assign
			SET
                                item_id='".$object->aid."',
				structure_id='".mysql_real_escape_string($object->sid)."'
				
		";
                if ($object->sid && $object->aid) {
                    $query = mysql_query($sql);
                    if (!$query) {
			echo $sql;
			echo "<br />";
                    }
                }
}

echo "ende<br>";

function price ($p) {
	$p = str_replace(',', '.', $p);
	$p = substr($p, 0, -2);
	return $p;
}

?>