以下德文主要向大家描述的是MySQL批量導入與執行程序的實際操作步驟以及MySQL批量導入與執行程序的實際應用代碼的描述,以下的文章就是對其具體的操作步驟以及具體的操作代碼的描述。
代碼如下:
- <?
- // 允許腳本在register globals =off 時工作
- $onoff =@ini_get('register_globals')||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 打開,調用 stripslashes_array)函數去掉轉義字符
- if (get_magic_quotes_gpc()) {
- $_POST = stripslashes_array($_POST);
- }
- ?>
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>MySQL批量導入和執行程序</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";
- }
- </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">MySQL批量導入和執行程序</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>
以上的相關內容就是對MySQL批量導入和執行程序的介紹,望你能有所收獲。