这段PHP代码可以用来备份MysqL数据库或者MysqL表
/**
* PHP代码备份MysqL数据库
*
* @param
* @arrange 512-笔记网: jb51.cc
**/
<?PHP
$Database_name = 'somedb';
$table = 'soMetable';
Define ('H','localhost'); define ('N','root') define ('P','password'); define ('T',$database_name);
MysqL_connect (H,N,P) or die (MysqL_error ()); MysqL_select_db (T) or die (MysqL_error ());
function Escape($v){return MysqL_real_escape_string($v);}
Define('FILE','C:/Program Files/EasyPHP 2.0b1/www/'. $table .'/'. date ('d').'-'. date (' m').'-' . date ('Y').'.PHP');
Define('FP',fopen(FILE,'w'));
$aa = MysqL_list_tables($database_name); while ($a = MysqL_fetch_row($aa))
{
$bb = MysqL_query ('SELECT * FROM'. $a[0].''); $tt = MysqL_num_rows($bb); $nb = MysqL_num_fields($bb);
If($tt>0)
{
$p = 'INSERT INTO'. $a[0]. " VALUES ';
$t = 0;
while ($b = MysqL_fetch_array($bb))
{
$ p .='(';
For ($i=0;$i<$nb,$i++)
{
if ($i==0)
{
$p .= "'$b[$i]'";
}
else
{
$p .=',''. Escape($b[$ i]). ''';
}
}
$t++;
if ($t<$tt)
{
$ p .='),'." n ";
}
else
{
$ p .=');'." n";
}
}
$p .= "nnn";
fwrite(FP,$p);
}
}
fclose(FP);
?>
/*** 来自编程之家 jb51.cc(jb51.cc) ***/
原文链接:https://www.f2er.com/php/528477.html