<?php 
include "../Run.php";
//获取数据库中的数据表
set_time_limit(0);
function list_tables ($database)  
 
{  
 
$rs = mysql_query("SHOW TABLES FROM $database");  
 
$tables = array();  
 
while ($row = mysql_fetch_row($rs)){  
 
$tables[] = $row[0];  
 
}  
 
mysql_free_result($rs);  
 
return $tables;  
 
}
//获取数据表中的字段名
function mysql_field($sel){
$result = mysql_query("select * from ".$sel);
while($field = mysql_fetch_field($result)){
	$back[] .= $field->name;

	}
	return $back;
}
//选择数据库
$list_tables = $cfg['SQL_SEL'];
$tables = list_tables($list_tables);
//循环每一个数据表

	foreach ($tables as $tables_name){
	if($tables_name != 'user_online'){
	//获取本数据表中的字段信息
		$field = mysql_field($tables_name);
		$field_nums = count($field);
		$zd = implode(",",$field);
			$sql = "SELECT * FROM $tables_name";
			$res = mysql_query($sql);
			$i = 0;
			$listnums=mysql_num_rows($res);
			while($f = mysql_fetch_row($res)){
			$sql_q =  "\$sql = \"INSERT INTO $tables_name ( $zd )VALUE("; 
			foreach($f as $v){
			$sql_c[] = "'".addslashes($v)."'";
			}
			$sqlstr = implode(",",$sql_c);	
			$sql_h =  ')"; mysql_query($sql);';
			$sql_str .= $sql_q.$sqlstr.$sql_h;
			$end = $i++%25 == 0?TRUE:FALSE;
			if($end == TRUE || $i== $listnums){
			$co[] = '0';
			$thisa = count($co);
			$text = '<?php '.$sql_str.' ?>';
			file_put_contents("../datas/".date("Y_m_d_H",time()).$thisa.".php",$text);
			$sql_c = NULL;
			$sql_str = NULL;
			$i++;
					}
				}
			}
		}
		
	