<?
require_once("config.php");
$sql1=mysql_connect($sugar_config['dbconfig']['db_host_name'],$sugar_config['dbconfig']['db_user_name'],$sugar_config['dbconfig']['db_password']);
mysql_select_db($sugar_config['dbconfig']['db_name']);
$sql2=mysql_connect("83.13.113.250","e5crm","e52005pkr");
mysql_select_db("e5crm");
$q=$GLOBALS['db']->query("select code,id from ecmproducts",$sql1);
while($r=$GLOBALS['db']->fetchByAssoc($q))
{
	$rr=$GLOBALS['db']->fetchByAssoc($GLOBALS['db']->query("select stan,cena,zamowione from stany where indeks='".$r['code']."'",$sql2));
	$stan=$rr['stan'];
	$cena=$rr['cena'];
	$zamowione=$rr['zamowione'];
	print "produkt:  ".$r['code'].", stan:  ".$stan.", cena:  ".$cena.", zamowione:  ".$zamowione;
	if($GLOBALS['db']->query("update ecmproducts set ems_ordered='".$zamowione."',ems_price='".$cena."',ems_qty_in_stock='".$stan."' where code='".$r['code']."'",$sql1))print "zapisano<br>";
	else print "nie zapisano<br>";
}
mysql_close($sql2);
mysql_close($sql1);
?>