<?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('topreef', $connection) or die("Konnte die Datenbank nicht waehlen.1");

echo "get items<br>";
// get items
$query = mysql_query('SELECT * FROM item_import') 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('topreef', $connection) or die("Konnte die Datenbank nicht waehlen.2");

// tax wrapper
$taxes = array(
	'19' => '1',
	'7'  => '3' 
);

echo "get hersteller<br>";
// get manufacturers
$sql = "SELECT * FROM manufacturers ORDER BY name";
$query = mysql_query($sql);
$manufacturers = array();
while($obj = mysql_fetch_object($query)) {
	$manufacturers[$obj->name] = $obj->id;
}

echo "update items<br>";
foreach ($data as $object) {
	
	$object->{'EK-Preis'} = substr($object->{'EK-Preis'},0,-4);
	$object->{'EK-Preis'} = str_replace(",",".",$object->{'EK-Preis'});
	$object->{'EK-Preis'} = (float)$object->{'EK-Preis'};
	
		$sql = "
			UPDATE items
			SET
				base_price='".mysql_real_escape_string($object->{'EK-Preis'})."'
			WHERE
				id='".$object->id."';
				
		";
		echo $sql;echo "<br />";
		//$query = mysql_query($sql);
		if (!$query) {
			echo $sql;
			echo "<br />";
		}
	
	
	
}


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

?>