Hello,
I want to make one script which executes on daily bases and checks each single table of the database called DB1 and then match with the other database DB2's tables (Both database have similar tables and table fields.)
So is there any simple way to do so?
What I have tried:
$copiedProducts = array();
foreach ($erpXML->store as $mainstore) {
$mainLocation = $mainstore->attributes()->id;
$mainLocation1 = (array)$mainLocation;
$dbConn = $mainstore->db;
$dbcon = new MeekroDB(CFG::$host, CFG::$user, CFG::$password, $dbConn);
$syd_products = $dbcon->query("SELECT * FROM " . CFG::$tblPrefix . "product");
foreach ($erpXML->store as $tostore) {
$toLocation = $tostore->attributes()->id;
$toDBConn = $tostore->db;
if(strtolower($mainLocation) != strtolower($toLocation)) {
$newLac = (array)$toLocation;
copy_product($syd_products, $toDBConn, $mainLocation1[0], $newLac[0]);
}
}
}
function copy_product($products, $db, $fromdb, $newLaca) {
global $copiedProducts, $cnt;
$cnt = 0;
$dbObj = (array)$db;
$dbCon = new MeekroDB(CFG::$host, CFG::$user, CFG::$password, $db);
foreach($products as $key=>$val) {
$store_prd = $dbCon->queryFirstRow("SELECT id, name FROM " . CFG::$tblPrefix . "product WHERE pid = '" . $val['pid'] . "'");
$newArrPrdQty = $newArr = array();
if(empty($store_prd) && !preg_match("/ST-(.*)/", $val["pid"])) {
$copiedProducts[$fromdb][$cnt]["todb"] = $newLaca;
$copiedProducts[$fromdb][$cnt]["pid"] = $val["pid"];
$cnt++;
$sortOrder = $dbCon->queryFirstRow("SELECT MAX(sort_order) as sort_order FROM " . CFG::$tblPrefix . "product");
$newArr["pid"] = $val["pid"];
$newArr["name"] = $val["name"];
$newArr["description"] = $val["description"];
$newArr["weight"] = $val["weight"];
$newArr["sort_order"] = $sortOrder["sort_order"] + 1;
$newArr["is_deleted"] = $val["is_deleted"];
$newArr["created_date"] = date("Y-m-d H:i:s");
$newArr["ignore_customer_app"] = $val["ignore_customer_app"];
$newArr["featured_prod"] = $val["featured_prod"];
$dbCon->insert(CFG::$tblPrefix . "product", String::processString($newArr));
$insertedId = $dbCon->insertId();
$newArrPrdQty["pid"] = $val["pid"];
$newArrPrdQty["product_id"] = $insertedId;
$newArrPrdQty["qty"] = "0";
$newArrPrdQty["price"] = "0.000000";
$newArrPrdQty["is_deleted"] = "";
$newArrPrdQty["created_date"] = date("Y-m-d H:i:s");
$newArrPrdQty["updatable"] = "1";
$dbCon->insert(CFG::$tblPrefix . "product_qty", String::processString($newArrPrdQty));
}
}
}
exit;