<?php

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


/*$connection=mysql_connect('localhost', 'root', '1234') or die ("Verbindungsversuch fehlgeschlagen");
mysql_select_db('intelectra', $connection) or die("Konnte die Datenbank nicht waehlen.");
*/
$connection=mysql_connect('localhost', 'intelectra_shop_', 'Wwja71!3') or die ("Verbindungsversuch fehlgeschlagen");
mysql_select_db('intelectra_shop__', $connection) or die("Konnte die Datenbank nicht waehlen.1");

$query = mysql_query('select * from manufacturers') or die("Anfrage nicht erfolgreich");
$manufacturers = array();
while($obj = mysql_fetch_object($query)) {
	$manufacturers[$obj->name] = $obj->id;
}

echo "get data<br>";
// get items
$query = mysql_query('SELECT * FROM import_artikelcsv') or die("Anfrage nicht erfolgreich");
$data = array();
while($obj = mysql_fetch_object($query)) {
	$data[] = $obj;
}

echo "imports<br>";
foreach ($data as $object) {
    $manufacturer_id = 1;
    if(isset($manufacturers[$object->ersatzteilvertreiber])) {
        $manufacturer_id = $manufacturers[$object->ersatzteilvertreiber];
    }
		$sql = "
			UPDATE items
			SET
				attribute_7='".mysql_real_escape_string($object->navisionid)."',
                                attribute_8='".mysql_real_escape_string($object->merkmale)."',
                                attribute_9='".mysql_real_escape_string($object->aufdrucke)."',
                                attribute_10='".mysql_real_escape_string($object->handlingeinheit)."',
                                attribute_11='".mysql_real_escape_string($object->handlingsifaktor)."',
                                attribute_12='".mysql_real_escape_string($object->verpackungseinheitfaktor)."',
                                ean_code='".mysql_real_escape_string($object->ean)."',
                                vendor_item_number='".mysql_real_escape_string($object->teilenrlieferant)."',
                                shipping_weight='".mysql_real_escape_string($object->gewicht)."',
                                manufacturer_id='".$manufacturer_id."'     
                        WHERE number='".$object->altenr."'
		";
                //echo $sql.'<br>';
		$query = mysql_query($sql);
		if (!$query) {
			echo $sql;
			echo "<br />";
		}
}

echo "ende<br>";

?>