Website in PHP + MYSQL. Third-party site provides XML upload. I process ready unloading on ODA. conditions and pass on your website in the database. You need to implement a batch implementation to reduce the load and data write time. Parsing goes through xpath. In foreach there is a SELECT, conditions with continue and 1 INSERT. How to break into packages - I'll never know.
foreach ($xmlTree->xpath('/doct//page/product') as $tree) { $prid = (array) $tree->product; $prid = $prid[0]; $pgid = (array) $tree->page; $pgid = $pgid[0]; //Проверяем, есть ли товар с таким id $ge = db::getInstance()->db()->query('SELECT id FROM goods_from_site WHERE product_id=?d', $prid); if(!empty($ge)){ continue; } db::getInstance()->db()->query('INSERT INTO `goods_from_site` (`product_id`, `rid2`) VALUES ("'.$prid.'","'.$pgid.'")'); }
foreach ($xmlTree->xpath('/doct//page/product') as $tree) { $prid = (array) $tree->product; $prid = $prid[0]; $pgid = (array) $tree->page; $pgid = $pgid[0]; //Проверяем, есть ли товар с таким id $ge = db::getInstance()->db()->query('SELECT id FROM goods_from_site WHERE product_id=?d', $prid); if(!empty($ge)){ continue; } db::getInstance()->db()->query('INSERT INTOforeach ($xmlTree->xpath('/doct//page/product') as $tree) { $prid = (array) $tree->product; $prid = $prid[0]; $pgid = (array) $tree->page; $pgid = $pgid[0]; //Проверяем, есть ли товар с таким id $ge = db::getInstance()->db()->query('SELECT id FROM goods_from_site WHERE product_id=?d', $prid); if(!empty($ge)){ continue; } db::getInstance()->db()->query('INSERT INTOgoods_from_site` (product_id,rid2) VALUES ("'. $ prid. '", "'. $ pgid. '") "); } - LEgXrinsert IGNORE into ...and you don’t need a check, it will only insert new rows. Plus, you need to go to the prepared expressions. before the loop, do$q=prepare('insert .... values(?,?), and in the loop execute$q->execute( array($prid,$pgid );(for PDO, in the case of mysqli you will have to do bind inside the loop. Up to 50% of the insert operation time in the database is taken by compiling a new query from the text - Mike