MySQL batch import operation steps and code

Source: Internet
Author: User

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:

 
 
  1. <?
  2. // Allow the script to work when register globals = off
  3. $ Onoff = @ ini_get ('register _ globals') | get_resource_var ('register _ globals ');
  4. If ($ onoff! = 1 ){
  5. @ Extract ($ _ POST, EXTR_SKIP );
  6. @ Extract ($ _ GET, EXTR_SKIP );
  7. }

Remove escape characters

 
 
  1. function stripslashes_array(&$array) {  
  2. while(list($key,$var) = each($array)) {  
  3. if ($key != 'argc' && $key != 'argv' && (strtoupper($key) != $key || ''.intval  
  4. ($key) == "$key")) {  
  5. if (is_string($var)) {  
  6. $array[$key] = stripslashes($var);  
  7. }  
  8. if (is_array($var)) {  
  9. $array[$key] = stripslashes_array($var);  
  10. }  
  11. }  
  12. }  
  13. return $array;  

If magic_quotes_gpc is enabled, call the stripslashes_array function to remove the escape character.

 
 
  1. if (get_magic_quotes_gpc()) {  
  2. $_POST = stripslashes_array($_POST);  
  3. }  
  4. ?> 
  5. <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> 

<Title> MySQL batch import and execution programs </title>

 
 
  1. <style type="text/css"> 
  2. body,td {  
  3. font-family: "sans-serif";  
  4. font-size: "12px";  
  5. line-height: "150%";  
  6. }  
  7. .INPUT {  
  8. FONT-SIZE: "12px";  
  9. COLOR: "#000000";  
  10. BACKGROUND-COLOR: "#FFFFFF";  
  11. height: "18px";  
  12. border: "1px solid #666666";  
  13. }  
  14. </style> 
  15. <body style="table-layout:fixed; word-break:break-all"> 
  16. <center> 
  17. <? 
  18. if ($_GET['action'] == "sql") {  
  19. $servername = isset($servername) ? $servername : 'localhost';  
  20. $dbusername = isset($dbusername) ? $dbusername : 'root';  
  21. $dbpassword = isset($dbpassword) ? $dbpassword : '';  
  22. $dbname = isset($dbname) ? $dbname : '';  
  23. }  
  24. if($doquery) {  
  25. if(@MySQL_connect($servername,$dbusername,$dbpassword) AND @MySQL_select_db($dbname))  

Echo "database connection execution! \ N ";

 
 
  1. }
  2. Else
  3. {
  4. Echo "error:". MySQL_error ();
  5. }
  6. $ A_query = explode (";", $ _ POST ['SQL _ query']);
  7. While (list (, $ query) = each ($ a_query )){
  8. $ Query = trim ($ query );
  9. If ($ query ){
  10. If (strstr ($ query, 'create table ')){
  11. Ereg ('create TABLE ([^] *) ', $ query, $ regs );
  12. MySQL_query ("drop table if exists $ regs [1]");
  13. Echo "<p> creating table:". $ regs [1]. "…… ";
  14. $ Result = @ MySQL_query ($ query );
  15. If ($ result)
  16. {
  17. Echo "successful! </P> \ n ";
  18. } Else {
  19. Echo "failed! </P> \ n ";
  20. }
  21. } Else {
  22. $ Result = @ MySQL_query ($ query );
  23. Echo ($ result )? "SQL statement successfully executed \ n": "error:". MySQL_error ();
  24. }
  25. }
  26. }
  27. MySQL_close ();
  28. }
  29. Elseif (connect ){
  30. If (@ MySQL_connect ($ servername, $ dbusername, $ dbpassword) AND @ MySQL_select_db ($ dbname )){

Echo "database connection execution! \ N ";

 
 
  1. } Else {
  2. Echo "error:". MySQL_error ();
  3. }
  4. }
  5. ?>
  6. <Table width = "760" border = "0" cellpadding = "3" cellspacing = "1" bgcolor = "# ffffff">
  7. <Tr class = "firstalt">

<Td align = "center"> MySQL batch import and execution programs </td>

 
 
  1. </Tr>
  2. <Form action = "? Action = SQL "method =" POST ">
  3. <Tr class = "secondalt">
  4. <Td align = "center"> Host:
  5. <Input name = "servername" type = "text" class = "INPUT" value = "<? = $ Servername?> ">
  6. User:
  7. <Input name = "dbusername" type = "text" class = "INPUT" size = "15" value = "<? = $ Dbusername?> ">
  8. Pass:
  9. <Input name = "dbpassword" type = "text" class = "INPUT" size = "15" value = "<? = $ Dbpassword?> ">
  10. DB:
  11. <Input name = "dbname" type = "text" class = "INPUT" size = "15" value = "<? = $ Dbname?> ">
  12. <Input name = "connect" type = "submit" class = "INPUT" value = "connection"> </td>
  13. </Tr>
  14. <Tr class = "firstalt">
  15. <Td align = "center"> <textarea name = "SQL _query" cols = "85" rows = "10"> </textarea> </td>
  16. </Tr>
  17. <Tr class = "secondalt">
  18. <Td align = "center"> <input type = "submit" name = "doquery" value = "execution" class = "input"> </td>
  19. </Tr>
  20. </Form>
  21. </Table>
  22. </Body>
  23. </Html>

The above content is an introduction to MySQL batch import and execution programs. I hope you will have some gains.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.