以下德文主要向大家描述的是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批量导入和执行程序的介绍,望你能有所收获。
【编辑推荐】