//File: query.php
//描述: 数据库批量导入脚本
//功能: 可进行单行和批量插入.
//作者: SworDs
//QQ: 78623269
//日期: -1-21
//其他:好老了啊,刚学PHP写的,连抄带查!.5.19从仓库里翻出来,。。。
error_reporting(7);
if ( function_exists('ini_get') ) {
$onoff = ini_get('register_globals');
} else {
$onoff = get_cfg_var('register_globals');
}
if ($onoff != 1) {
@extract($_POST, EXTR_SKIP);
@extract($_GET, EXTR_SKIP);
}
// 去掉转义字符
function stripslashes_array(&$array) {
while(list($key,$var) = each($array)) {
if ($key != 'argc' && $key != 'argv' && (strtoupper($key) != $key || ''.intval($key) == "$key")) {
if (is_string($var)) {
$array[$key] = stripslashes($var);
}
if (is_array($var)) {
$array[$key] = stripslashes_array($var);
}
}
}
return $array;
}
// 判断 magic_quotes_gpc 状态
if (get_magic_quotes_gpc()) {
$_POST = stripslashes_array($_POST);
}
?>
数据库批量导入脚本 by SworDs
body,td {
font-family: "sans-serif";
font-size: "12px";
line-height: "150%";
}
.INPUT {
FONT-SIZE: "12px";
COLOR: "#000000";
BACKGROUND-COLOR: "#FFFFFF";
height: "18px";
border: "1px solid #666666";
}
.firstalt {BACKGROUND-COLOR: "#EFEFEF"}
.secondalt {BACKGROUND-COLOR: "#F5F5F5"}
if ($_GET['action'] == "sql") {
$servername = isset($servername) ? $servername : 'localhost';
$dbusername = isset($dbusername) ? $dbusername : 'root';
$dbpassword = isset($dbpassword) ? $dbpassword : '';
$dbname = isset($dbname) ? $dbname : '';
}
if($doquery) {
if(@mysql_connect($servername,$dbusername,$dbpassword) AND @mysql_select_db($dbname))
{
echo "数据库连接执行!\n";
}
else
{
echo "出错: ".mysql_error();
}
$a_query = explode(";",$_POST['sql_query']);
while (list(,$query) = each($a_query)) {
$query = trim($query);
if ($query) {
if (strstr($query,'CREATE TABLE')) {
ereg('CREATE TABLE ([^ ]*)',$query,$regs);
mysql_query("DROP TABLE IF EXISTS $regs[1]");
echo "
正在建立表: ".$regs[1]." …… ";
$result=@mysql_query($query);
if ($result)
{
echo "成功!
\n";
} else {
echo "失败!
\n";
}
} else {
$result=@mysql_query($query);
echo ($result) ? "SQL语句成功执行\n" : "出错: ".mysql_error();
}
}
}
mysql_close();
}
elseif(connect){
if(@mysql_connect($servername,$dbusername,$dbpassword) AND @mysql_select_db($dbname)) {
echo "数据库连接执行!\n";
}else{
echo "出错: ".mysql_error();
}
}
?>