< ?
if($table=="")exit();
mysql_connect("localhost","name","password");
mysql_select_db("database");
$result = mysql_query("select * from $table");
if(mysql_num_rows($result) < = 0) exit();
echo "开始转换数据到文本...
";
$handle = fopen("$table.txt","w");
$numfields = mysql_num_fields($result);
fputs($handle,$numfields."
");
for($k=0;$k< mysql_num_rows($result);$k )
{
$msg = mysql_fetch_row($result);
for($i=0;$i< $numfields;$i )
{
$msg[$i] = str_replace("
","&&php2000mysqlreturn&&",$msg[$i]);
$msg[$i] = str_replace("
" ,"&&php2000mysqlreturn&&",$msg[$i]);
fputs($handle,$msg[$i]."
");
}
fputs($handle,"------- php2000 dump data program V1.0 for MySQL --------
");
}
fclose($handle);
echo "ok";
?>
导入的程序如下:用法同上面!
< ?
if($table=="")exit();
mysql_connect("localhost","name","password");