📄 sql.php
字号:
function writefile($data,$method='a'){
global $HTTP_POST_VARS;
$file="$HTTP_POST_VARS[dir]/$HTTP_POST_VARS[filename]_pg$HTTP_POST_VARS[page].php";
$fp=fopen($file,"$method");
flock($fp,2);
fwrite($fp,$data);
}
$HTTP_POST_VARS["logosrc"]="$dir/{$filename}_faisunsqllogo.gif";
if(!$HTTP_POST_VARS[lastcreate]) $HTTP_POST_VARS[lastcreate]=0;
if(!$HTTP_POST_VARS[lastinsert]) $HTTP_POST_VARS[lastinsert]=0;
if(!$HTTP_POST_VARS[page]) $page=$HTTP_POST_VARS[page]=0;
$lastcreate_temp=$HTTP_POST_VARS[lastcreate];
$tablearr=array();
while (count($table)&&list($key,$val)=each($table)) {
if ($val=="yes") {
$tablearr[]=$key;
}
}
if(!is_dir("$dir") and !@mkdir("$dir",0777)){
fheader();
echo "
<BR><BR><BR><center>目录'$dir'不存在且不能自动创建!请检查目录权限(权限为 777 方可写文件)。</center><BR><BR><BR>
";
ffooter();
exit;
}
//是否有多余的文件
$dfileNo=0;
$open=opendir($dir);
$delhtml="";
while($afilename=readdir($open) and !$HTTP_POST_VARS[filedeled]){
$checked="";
if(eregi("^{$filename}_pg[0-9]+\.php$",$afilename) or $afilename=="{$filename}.php" or $afilename=="{$filename}_faisunsqllogo.gif"){
$checked="checked";
}if(is_file("$dir/$afilename")){
$delhtml.="
<tr bgcolor='#EBEFFC'>
<td>$afilename</td>
<td>".date("Y-m-d",filectime("$dir/$afilename"))."</td>
<td>".filesize("$dir/$afilename")." B</td>
<td align='center'>
<input name='dfile[$dfileNo]' type='checkbox' value='$dir/$afilename' $checked>
</td>
</tr>
";
$dfileNo++;
}
}
if($dfileNo){
$HTTP_POST_VARS[filedeled]=1;
fheader();
echo "
'$dir/'中以下文件已存在,它们可能被覆盖或成为额外的文件。<br>
您可以有选择地删除它们或返回上一步重新设定:<br>
<table width='500' border='0' cellspacing='1' cellpadding='3' bgcolor='#1B56C5' align=center>
<tr>
<td colspan='4'><font color='#FFFFFF'><strong>选择要删除的文件:</strong></font></td>
</tr>
<tr bgcolor='#D6DFF7'>
<td width='31%'><strong>文件名</strong></td>
<td width='32%'><strong>修改日期</strong></td>
<td width='21%'><strong>大小</strong></td>
<td width='16%' nowrap><strong>选择</strong><input type='checkbox' name='checkbox' value='' onclick='selrev();'>
</td>
</tr>
$delhtml
";
echo "
</table>
<br>
<script language='JavaScript'>
<!--
function selrev() {
with(myform) {
for(i=0;i<elements.length;i++) {
thiselm = elements[i];
if(thiselm.name.match(/dfile\[\w+\]/))
thiselm.checked = !thiselm.checked;
}
}
}
</script>
";
fbutton('submit','dosubmit','删除并继续');
fbutton('reset','doreset','重置');
fbutton('button','dogoback','返回修改','onclick=\'history.back();\'');
ffooter();
exit;
}
//删除多余文件
if($HTTP_POST_VARS[filedeled]==1){
while(list($key,$val)=each($dfile)){
if($val) unlink($val);
}
}
$HTTP_POST_VARS[filedeled]=2;
if($HTTP_POST_VARS[page]==0){
//写入图片
$fp=fopen($HTTP_POST_VARS["logosrc"],"w");
flock($fp,2);
fwrite($fp,logocode());
fclose($fp);
$HTTP_POST_VARS[page]=1;
fheader();
echo "<table width='400' border='0' cellspacing='1' cellpadding='3' bgcolor='#1B56C5'>
<tr><td><font color='#FFFFFF'><strong>目录权限正确</strong></font></td></tr>
<tr bgcolor='#D6DFF7'>
<td><br>
经测试,该目录可以写入文件,LOGO图片已成功写入。<br>
下面开始导出数据并保存在服务器中。<br><br>
导出过程中可能会出现运行超时,<br>
在那种情况下,请刷新本页并点击“重试”重新发送信息,<br>
即可继续导出。<br><br>
</td>
</tr>
</table><br>
";
fbutton('submit','dosubmit','继续导出');
ffooter();
exit;
}
writefile("<? \n","w");
for($i=$HTTP_POST_VARS[lastcreate];$i<count($tablearr);$i++){
$tableid=$i;
sqldumptable($tablearr[$i],1);
}
//结束最后文件
$data="
echo '<center><BR><BR><BR><BR>完成。所有数据都已经导入数据库中。</center></body></html>';
exit;
?>
";
writefile("$data");
//写入引导文件
$data='<?
$usedumppass=1; //是否使用导入密码。如果您忘记了导入密码,请把值改为 0 。
set_time_limit(30);
while(list($key,$val)=each($HTTP_POST_VARS)){
$$key=$val;
}reset($HTTP_POST_VARS);
?><html><head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>faisunSQL 数据库自导入程序 — Powerd By faisun</title>
<style type="text/css">body,td {font-family: "宋体";font-size: 10.8pt;}</style></head>
<body link="#0000FF" vlink="#0000FF" alink="#0000FF">
<center><a href="http://faisun.1816.net" target="_blank"><img src="'.$filename.'_faisunsqllogo.gif" border=0 width=300 height=71></a><br>
<font color=red>本文件由 faisun 编写的 <a href="http://faisun.1816.net" target="_blank">faisunSQL自导入数据库备份程序</a> 生成</font><HR size=1>
</center><script language=javascript>noerrer=true;</script>
<?
if(!$HTTP_POST_VARS["action"]){
?>
<form name="configform" method="post" action="">
<table width="400" border="0" bgcolor="#1B56C5" align=center>
<tr><td><font color="#FFFFFF"><strong>导入数据库配置</strong></font></td></tr>
<tr bgcolor="#D6DFF7"><td>
服务器:<input name="db_host" value="'.$back_host.'" type="text"><br>
数据库:<input name="db_dbname" value="'.$back_dbname.'" type="text"><br>
该数据库不存在时自动创建:<input name="db_autocreate" value="1" type="checkbox" '.$back_autocreate.'><br>
用户名:<input name="db_username" value="" type="text"><br>
密 码:<input name="db_password" value="" type="password"><br>
导入密码:<input name="db_pass" value="" type="password">
<br>
<tr><td align=center>
<input name="action" type="submit" value=" 导入 ">
</td></tr></table></form></body></html>
<?
exit;
}
if(md5($db_pass)!="'.md5($back_pass).'" and $usedumppass) die("导入密码不正确!如果您忘记了导入密码,请把本源文件开头的 \$usedumppass 的值改为 0 。");
@mysql_connect($db_host,$db_username,$db_password) or die("<BR><BR><center>不能连接服务器!请返回检查您的配置。</center>");
if(!@mysql_select_db($db_dbname)){
if(!$db_autocreate){echo "<BR><BR><center>数据库[{$db_dbname}]不存在!请返回检查您的配置。</center>";exit; }
if(!mysql_query("CREATE DATABASE `$db_dbname`")){echo "<BR><BR><center>数据库[{$db_dbname}]不存在且自动创建失败!请返回检查您的配置。</center>";exit;}
mysql_select_db("$db_dbname");
}
function query($sql){
if(!mysql_query($sql)) echo "<BR><BR><font color=red>MySQL语句错误!您可能发现了程序的BUG!<a href=\"mailto:faisun@sina.com\">请报告开发者。</a>
<BR>语句:<XMP>$sql</XMP>错误信息: ".mysql_error()." </font><script language=javascript>noerrer=false;</script>" ;
}
function create($table,$sql){
query("DROP TABLE IF EXISTS `$table`;");
query("CREATE TABLE `$table` ".$sql);
}
function insert($table,$data){
query("INSERT INTO `$table` VALUES ($data);");
}
if(!$HTTP_POST_VARS[loadpage]){$HTTP_POST_VARS[loadpage]=1;}
$totalpage='.$HTTP_POST_VARS[page].';
include("'.$filename.'_pg$HTTP_POST_VARS[loadpage].php");
echo "<center><form name=myform method=\'post\' action=\'\'>";
$HTTP_POST_VARS[loadpage]++;
while(list($key,$val)=each($HTTP_POST_VARS)){
echo "<input name=\'$key\' value=\'$val\' type=\'hidden\'>\n";
}
echo "<BR><BR>正在导入数据到数据库\'$HTTP_POST_VARS[db_dbname]\'……<BR><BR>本页运行完成! 正在自动进入<a href=\'javascript:myform.submit();\'>第 $HTTP_POST_VARS[loadpage] 页</a>,共 $totalpage 页……
<script language=\'Javascript\'>
if(noerrer)myform.submit();
</script>
</form></center>
";
?>
<body></html>
';
$file="$dir/{$filename}.php";
$fp=fopen($file,"w");
flock($fp,2);
fwrite($fp,$data);
fclose($fp);
fheader();
echo "
<BR><BR><BR><BR><BR><BR><center>完成。
<BR><BR>数据库'$db_dbname'已全部保存到文件夹'$dir'中,共 $page 页,".($page+2)." 个文件。
<BR><BR>将此文件夹置于服务器可访问目录,并运行'$filename.php'即可将数据导入。</center><BR><BR><BR>
";
ffooter();
exit;
}else if($HTTP_POST_VARS[back_type]=="download"){//////////////////////// Sent Data ////////////////////////////
function dealdata($data){
echo "$data";
}
header("Content-disposition: filename=$db_dbname(".date("Ymj",time()).")_faisunsql.php");
header("Content-type: unknown/unknown");
echo '<?
set_time_limit(30);
function getmicrotime(){
list($usec, $sec) = explode(" ",microtime());
return ((float)$usec + (float)$sec);
}
$time_start = getmicrotime();
while(list($key,$val)=each($HTTP_POST_VARS)){
$$key=$val;
}reset($HTTP_POST_VARS);
?>
<html><head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>faisunSQL 数据库自导入程序 — Powerd By faisun</title><style type="text/css">body,td {font-family: "宋体";font-size: 10.8pt;}</style></head>
<body link="#0000FF" vlink="#0000FF" alink="#0000FF">
<center>
<font color=red>本文件由 faisun 编写的 <a href="http://faisun.1816.net" target="_blank">faisunSQL自导入数据库备份程序</a> 生成</font><HR size=1>
</center>
<?
if(!$HTTP_POST_VARS["action"]){
?>
<form name="configform" method="post" action=""><table width="400" border="0" bgcolor="#1B56C5" align=center>
<tr><td><font color="#FFFFFF"><strong>导入数据库配置</strong></font></td></tr>
<tr bgcolor="#D6DFF7"><td>
服务器:<input name="db_host" value="'.$back_host.'" type="text"><br>
数据库:<input name="db_dbname" value="'.$back_dbname.'" type="text"><br>
该数据库不存在时自动创建:<input name="db_autocreate" value="1" type="checkbox" '.$back_autocreate.'><br>
显示导入过程:<input name="back_showlog" value="1" type="checkbox" '.$back_showlog.'><br>
用户名:<input name="db_username" value="" type="text"><br>
密 码:<input name="db_password" value="" type="password"><br>
<br>
<tr><td align=center>
<input name="action" type="submit" value=" 导入 ">
</td></tr></table></form></body></html>
<?
exit;
}
@mysql_connect($db_host,$db_username,$db_password) or die("<BR><BR><center>不能连接服务器!请返回检查您的配置。</center>");
if(!@mysql_select_db($db_dbname)){
if(!$db_autocreate){echo "<BR><BR><center>数据库[{$db_dbname}]不存在!请返回检查您的配置。</center>";exit; }
if(!mysql_query("CREATE DATABASE `$db_dbname`")){echo "<BR><BR><center>数据库[{$db_dbname}]不存在且自动创建失败!请返回检查您的配置。</center>";exit;}
else if($back_showlog) echo "<BR><BR>创建数据库[{$db_dbname}]...OK.";
mysql_select_db("$db_dbname");
}
function query($sql){
if(!mysql_query($sql)) echo "<BR><font color=red>MySQL语句错误!您可能发现了程序的BUG!<a href=\"mailto:faisun@sina.com\">请报告开发者。</a>
<BR>语句:<XMP>$sql</XMP><BR>错误信息: ".mysql_error()." </font>" ;
}
function create($table,$sql){
global $back_showlog,$firstinsert;
if($back_showlog){$firstinsert=1;echo "\n<BR><BR>创建数据表[$table]...";}
query("DROP TABLE IF EXISTS `$table`;");
query("CREATE TABLE `$table` ".$sql);
}
function insert($table,$data){
global $back_showlog,$firstinsert;
if($back_showlog and $firstinsert){$firstinsert=0; echo "\n<BR>添加数据到数据表[$table]...";}
query("INSERT INTO `$table` VALUES ($data);");
}
';
////// 开头部分结束 ////////
while (count($table)&&list($key,$val)=each($table)) {
if ($val=="yes") {
sqldumptable($key,0);
}
}
echo "
\$time_end = getmicrotime();\$time = \$time_end - \$time_start;
echo \"<BR><BR>完成。所有数据已成功导入到 [\$db_dbname],运行时间 \$time 秒。\";
?></body></html>";
exit;
}
}
?>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -