<form id=
"form1"
name=
"form1"
method=
"post"
action=
""
>
【数据库SQL文件】:<input id=
"sqlFile"
name=
"sqlFile"
type=
"file"
/>
<input id=
"submit"
name=
"submit"
type=
"submit"
value=
"还原"
/>
</form>
<?php
require_once
((dirname(
__FILE__
).'/../../
include
/config.php'));
if
( isset (
$_POST
['sqlFile'] ) )
{
$file_name
=
$_POST
['sqlFile'];
$dbhost
=
$cfg_dbhost
;
$dbuser
=
$cfg_dbuser
;
$dbpass
=
$cfg_dbpwd
;
$dbname
=
$cfg_dbname
;
set_time_limit(0);
$fp
= @
fopen
(
$file_name
,
"r"
)
or
die
(
"不能打开SQL文件 $file_name"
);
mysql_connect(
$dbhost
,
$dbuser
,
$dbpass
)
or
die
(
"不能连接数据库 $dbhost"
);
mysql_select_db(
$dbname
)
or
die
(
"不能打开数据库 $dbname"
);
echo
"<p>正在清空数据库,请稍等....<br>"
;
$result
= mysql_query(
"SHOW tables"
);
while
(
$currow
=mysql_fetch_array(
$result
))
{
mysql_query(
"drop TABLE IF EXISTS $currow[0]"
);
echo
"清空数据表【"
.
$currow
[0].
"】成功!<br>"
;
}
echo
"<br>恭喜你清理MYSQL成功<br>"
;
echo
"正在执行导入数据库操作<br>"
;
exec
(
"mysql -u$cfg_dbuser -p$cfg_dbpwd $cfg_dbname < "
.
$file_name
);
echo
"<br>导入完成!"
;
mysql_close();
}
?>