The following German text mainly describes the actual steps for MySQL batch import and execution, as well as the actual application code for MySQL batch import and execution, the following article describes the specific operation steps and specific operation code.
The Code is as follows:
- <?
- // Allow the script to work when register globals = off
- $ Onoff = @ ini_get ('register _ globals') | get_resource_var ('register _ globals ');
- If ($ onoff! = 1 ){
- @ Extract ($ _ POST, EXTR_SKIP );
- @ Extract ($ _ GET, EXTR_SKIP );
- }
Remove escape characters
- 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;
- }
If magic_quotes_gpc is enabled, call the stripslashes_array function to remove the escape character.
- if (get_magic_quotes_gpc()) {
- $_POST = stripslashes_array($_POST);
- }
- ?>
-
-
- <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<Title> MySQL batch import and execution programs </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>
-
- <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 "database connection execution! \ N ";
- }
- Else
- {
- Echo "error:". 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> creating table:". $ regs [1]. "…… ";
- $ Result = @ MySQL_query ($ query );
- If ($ result)
- {
- Echo "successful! </P> \ n ";
- } Else {
- Echo "failed! </P> \ n ";
- }
- } Else {
- $ Result = @ MySQL_query ($ query );
- Echo ($ result )? "SQL statement successfully executed \ n": "error:". MySQL_error ();
- }
- }
- }
- MySQL_close ();
- }
- Elseif (connect ){
- If (@ MySQL_connect ($ servername, $ dbusername, $ dbpassword) AND @ MySQL_select_db ($ dbname )){
Echo "database connection execution! \ N ";
- } Else {
- Echo "error:". MySQL_error ();
- }
- }
- ?>
- <Table width = "760" border = "0" cellpadding = "3" cellspacing = "1" bgcolor = "# ffffff">
- <Tr class = "firstalt">
<Td align = "center"> MySQL batch import and execution programs </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 = "connection"> </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 = "execution" class = "input"> </td>
- </Tr>
- </Form>
- </Table>
- </Body>
- </Html>
The above content is an introduction to MySQL batch import and execution programs. I hope you will have some gains.