7 PHP转移大量数据

<?php
require_once("lib/class.database.php");
 
define("TEST_DB_HOST", "");
define("TEST_DB_USER", "");
define("TEST_DB_PASSWORD", "");
define("TEST_DB_DB", "");
 
define("TEST_DB_HOST", "");
define("TEST_DB_USER", "");
define("TEST_DB_PASSWORD", "");
define("TEST_DB_DB", "");
 
define("DB_CHARSET", "utf8");
 
/*
 * 大量数据转移页面
 * 使用每次转移100条数据,跳转页面,来达到防止运行过多数据转移时PHP运行超时
 * 请访问 	transferBigData.php
 */
$TT_DB		=	New Database();
$dbName		=	"TEST";		//需要手动修改
$re			=	$TT_DB->connect(constant(strtoupper($dbName) . "_DB_HOST"), constant(strtoupper($dbName) . "_DB_USER"), constant(strtoupper($dbName) . "_DB_PASSWORD"), constant(strtoupper($dbName) . "_DB_DB"),DB_CHARSET);
 
 
$dataNum	=	1124780;				//需要手动修改
$pagesize	=	10000;
$pages		=	intval($dataNum/$pagesize)+1;
$page		=	isset($_GET['page']) ? $_GET['page'] : 0;
$start		=	$page*$pagesize;
 
if(is_numeric($page) && $page>=0){
 
	$sql1		=	"SELECT * FROM `` LIMIT ".$start." , ".$pagesize;		//需要手动修改
	//echo $sql1;
	$smsResult	=	$TT_DB->fetchArrs($sql1);	
	unset($TT_DB);
 
	$TEST_DB		=	New Database();
	$dbName2	=	"TEST";				//需要手动修改
	$TEST_DB->connect(constant(strtoupper($dbName2) . "_DB_HOST"), constant(strtoupper($dbName2) . "_DB_USER"), constant(strtoupper($dbName2) . "_DB_PASSWORD"), constant(strtoupper($dbName2) . "_DB_DB"),DB_CHARSET);
 
	foreach ($smsResult as $v){
		$sql			=	"INSERT INTO `` (`id` ,`` ,`` ,`` ,`` ,``) VALUES ('{$v['id']}', '{$v['']}', '{$v['']}', '{$v['']}', '{$v['']}','{$v['']}');";															//需要手动修改
		echo $sql;
		$insertResult	=	$TEST_DB->query($sql);
		if($insertResult==false){
			echo "失败<br />";
			exit();
		}
	}
 
	if($page<$pages){
		echo "<script>location.href='transferBigData.php?page=".($page+1)."'</script>";
	}else{
		echo "数据转移成功";
	}	
 
}

Related posts:

Leave a Reply

Your email address will not be published.