脚本宝典收集整理的这篇文章主要介绍了oa系统信用盘出租-php定时备份数据库数据,导出sql文件,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
$host="127.0.0.1";//数据库地址
$dbname="apiadmin";//这里配置数据库名
$username="root";//用户名
$passw="root";//这里配置密码
$filename=date("Y-m-d_H-i-s")."-".$dbname.".sql";
header("Content-disposition:filename=".$filename);//所保存的文件名
header("Content-tyPE:application/octetstream");
header("PRagma:no-cache");
header("Expires:0");
//备份数据
$i = 0;
$crlf="\r\n";
global $dbconn;
$dbconn = MysqL_connect($host,$username,$passw);//数据库主机,用户名,密码
$db = MysqL_select_db($dbname,$dbconn);
MysqL_query("SET names ‘utf8‘");
$tables =MysqL_list_tables($dbname,$dbconn);
$num_tables = @MysqL_numrows($tables);
print "-- filename=".$filename;
while($i < $num_tables)
{
$table=MysqL_tablename($tables,$i);
print $crlf;
echo get_table_structure($dbname,$table,$crlf).";$crlf$crlf";
//echo get_table_def($dbname,$crlf).";$crlf$crlf";
echo get_table_content($dbname,$crlf);
$i++;
}
//}
function get_table_structure($db,$crlf)
{
global $drop;
$schema_create = "";
if(!empty($drop)){ $schema_create .= "DROP TABLE IF EXISTS $table
;$crlf";}
$result =MysqL_db_query($db,"SHOW CREATE TABLE $table");
$row=MysqL_fetch_array($result);
$schema_create .= $crlf."-- ".$row[0].$crlf;
$schema_create .= $row[1].$crlf;
Return $schema_create;
}
//获得表内容
function get_table_content($db,$crlf)
{
$schema_create = "";
$temp = "";
$result = MysqL_db_query($db,"SELECT * From $table");
$i = 0;
while($row = MysqL_fetch_row($result))
{
$schema_insert = "INSERT INTO $table
VALUES (";
for($j=0; $j<MysqL_num_fields($result);$j++)
{
if(!isset($row[$j]))
$schema_insert .= " NULL,";
elseif($row[$j] != "")
$schema_insert .= " ‘".addslashes($row[$j])."‘,";
else
$schema_insert .= " ‘‘,";
}
$schema_insert = ereg_replace(",$","",$schema_insert);
$schema_insert .= ");$crlf";
$temp = $temp.$schema_insert ;
$i++;
}
return $temp;
}
//usleep适用于PHP5.0以上,定时
function do_cron(){usleep(1);write_txt();}
while(1){do_cron();}?>
以上是脚本宝典为你收集整理的oa系统信用盘出租-php定时备份数据库数据,导出sql文件全部内容,希望文章能够帮你解决oa系统信用盘出租-php定时备份数据库数据,导出sql文件所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。