想要将一个数据库备份到其他数据库 [英] Want to get backup of one database to other database

查看:68
本文介绍了想要将一个数据库备份到其他数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



我想制作一个在每日基础上执行的脚本,并检查数据库中每个名为DB1的单个表,然后与其他数据库DB2匹配tables(两个数据库都有类似的表和表字段。)



那么有没有简单的方法呢?



我尝试了什么:



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;
			//$copiedProducts[$mainLocation1[0]] = $mainLocation1[0];
			copy_product($syd_products, $toDBConn, $mainLocation1[0], $newLac[0]);
		}
	}//exit;
}

//pre($copiedProducts,1);
//exit;
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++;
			//return true;

//			$sortOrder = $dbCon->queryFirstRow("SELECT sort_order FROM " . CFG::$tblPrefix . "product order by sort_order desc ");
			$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"];
			//pre($newArr,1);

			$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;
}
exit;

推荐答案

copiedProducts = array() ;
foreach
copiedProducts = array(); foreach (


erpXML-> store as
erpXML->store as


mainstore){
mainstore) {


这篇关于想要将一个数据库备份到其他数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆