<?
set_time_limit(0);
//include_once("inc/auth.inc.php");
include_once("inc/conn.php");
include_once("inc/header.inc.php");
include_once("inc/utility_file.php");
$conn= mysql_connect("xx.xx.xx.xx:3336", "sun", "myoa888") or die("Could not connect: " . mysql_error());//第二套OA的数据库
//解决乱码问题:
@mysql_query("SET character_set_connection=gb2312, character_set_results=gb2312, character_set_client=binary",$conn);
//2.mysql_select_db()...选择数据数据库
mysql_select_db('TD_OA',$conn);
mysql_query( "set names 'gb2312'");
if (!$conn)
{
die('Could not connect: ' . mysql_error());
}
$TABLES="DEPARTMENT,USER,USER_EXT,USER_PRIV";//需要同步哪些数据表,直接添加表名称就可以了
$TEMP_ARRAY=explode(",",$TABLES);
$ARRAY_COUNT1=sizeof($TEMP_ARRAY);
if($TEMP_ARRAY[$ARRAY_COUNT1-1]=="")$ARRAY_COUNT1--;
for($T=0;$T< $ARRAY_COUNT1;$T++)
{
//---------------- 获得DROP TABLE语句 -----------------------
$TABLE_NAME=$TEMP_ARRAY[$T];
$drop_sql="DROP TABLE IF EXISTS `$TABLE_NAME`;";
//---------------- 获得CREATE语句 -----------------------
$query = "SHOW CREATE TABLE `$TABLE_NAME`";
$cursor= exequery(TD::conn(),$query);
if($ROW = mysql_fetch_row($cursor))
$CREATE_STR=$ROW[1];
$create_sql= $CREATE_STR.";";
//---------------- 获得INSERT语句 -----------------------
$COUNT = 0;
$INSERT_STR = "";
$query = "SELECT * FROM `$TABLE_NAME`";
$cursor= exequery(TD::conn(),$query);
$FIELD_NUM=mysql_num_fields($cursor);
while($ROW = mysql_fetch_row($cursor))
{
if($COUNT % 5000 == 0)
{
if($INSERT_STR != "")
{
$INSERT_STR = td_trim($INSERT_STR).";\n";
}
$INSERT_STR = "INSERT INTO `$TABLE_NAME` VALUES \n";
}
$VALUE_STR = "";
for($I = 0; $I < $FIELD_NUM; $I++) {
$VALUE_STR .= "'".mysql_real_escape_string($ROW[$I])."',";//mysql_escape_string
}
$INSERT_STR .= "(".td_trim($VALUE_STR)."),\n";
$COUNT++;
}
if($INSERT_STR != "")
{
$INSERT_STR = td_trim($INSERT_STR).";\n";
$insert_sql= $INSERT_STR;
}
echo $drop_sql;
mysql_query($drop_sql,$conn);
echo "<hr>";
echo $create_sql;
mysql_query($create_sql,$conn);
echo "<hr>";
echo $insert_sql;
mysql_query($insert_sql,$conn);
echo "<hr>";
}
mysql_close($conn);
echo "同步成功,去第二个OA里重新生成缓存!系统资源管理-->缓存数据管理-->重新生成缓存!";
?>
|