mkdir($CopyName, 0700);
$sql="SHOW TABLES";
$result = mysql_query($sql) or die(mysql_errno().mysql_error());
while($data=mysql_fetch_row($result)) {
$fp = fopen($CopyName.'/'.$data[0].'.sql', 'a');
if ( $fp ) {
$query = "TRUNCATE TABLE `".$data[0]."`;\r\n";
fwrite ($fp, $query);
$sql_data = 'SELECT * FROM `'.$data[0].'`';
$result_data = mysql_query($sql_data) or die(mysql_errno().mysql_error());
while( $data2=mysql_fetch_row($result_data) ) {
$query = '';
foreach ($data2 as $val) {
if ( is_null($val) ) $val = 'NULL';
else $val = "'".mysql_escape_string($val)."'";
if ( $query == '' ) $query = $val;
else $query .= ','.$val;
}
$query = "INSERT INTO `".$data[0]."` VALUES (".$query.");\r\n";
fwrite ($fp, $query);
}
fclose ($fp);
}
}