程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 數據庫知識 >> MYSQL數據庫 >> 關於MYSQL數據庫 >> MySQL數據庫批量導入腳本

MySQL數據庫批量導入腳本

編輯:關於MYSQL數據庫

<?PHP
//File: query.PHP
//描述: 數據庫批量導入腳本
//功能: 可進行單行和批量插入.
//作者: SWords
//QQ: 78623269
//日期: 2005-1-21
//其他:好老了啊,剛學PHP寫的,連抄帶查!2006.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);
}
?>
<Html>
<head>
<meta http-equiv="Content-Type" content="text/Html; charset=gb2312">
<title>數據庫批量導入腳本 by SWords</title>
<style type="text/CSS">
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"}
</style>
</head>
<body style="table-layout:fixed; Word-break:break-all">
<center>

<?
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 "<p>正在建立表: ".$regs[1]." …… ";
$result=@MySQL_query($query);
if ($result)
{
echo "成功!</p>\n";
} else {
echo "失敗!</p>\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();
}
}
?>
<table width="760" border="0" cellpadding="3" cellspacing="1" bgcolor="#ffffff">
<tr class="firstalt">
<td align="center">數據庫批量導入腳本 By SWords</td>
</tr>
<form action="?action=sql" method="POST">
<tr class="secondalt">
<td align="center">Host:
<input name="servername" type="text" class="INPUT" value="<?=$servername?>">
User:
<input name="dbusername" type="text" class="INPUT" size="15" value="<?=$dbusername?>">
Pass:
<input name="dbpassword" type="text" class="INPUT" size="15" value="<?=$dbpassWord?>">
DB:
<input name="dbname" type="text" class="INPUT" size="15" value="<?=$dbname?>">
<input name="connect" type="submit" class="INPUT" value="連接"></td>
</tr>
<tr class="firstalt">
<td align="center"><textarea name="sql_query" cols="85" rows="10"></textarea></td>
</tr>
<tr class="secondalt">
<td align="center"><input type="submit" name="doquery" value="執行" class="input"></td>
</tr>
</form>
</table>
</body>
</Html>

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved