home *** CD-ROM | disk | FTP | other *** search
/ PC World 2005 April / PCWorld_2005-04_cd.bin / akce / web / phptriad / phptriad2-2-1.exe / htdocs / phpmyadmin / ldi_check.php < prev    next >
PHP Script  |  2002-01-06  |  3KB  |  101 lines

  1. <?php
  2. /* $Id: ldi_check.php,v 1.11 2001/11/23 01:03:20 loic1 Exp $ */
  3.  
  4.  
  5. /**
  6.  * This file checks and builds the sql-string for
  7.  * LOAD DATA INFILE 'file_name.txt' [REPLACE | IGNORE] INTO TABLE table_name
  8.  *    [FIELDS
  9.  *        [TERMINATED BY '\t']
  10.  *        [OPTIONALLY] ENCLOSED BY "]
  11.  *        [ESCAPED BY '\\' ]]
  12.  *    [LINES TERMINATED BY '\n']
  13.  *    [(column_name,...)]
  14.  */
  15.  
  16.  
  17. /**
  18.  * Gets some core scripts
  19.  */
  20. require('./libraries/grab_globals.lib.php');
  21. require('./libraries/common.lib.php');
  22.  
  23.  
  24. /**
  25.  * The form used to define the query has been submitted -> do the work
  26.  */
  27. if (isset($btnLDI) && ($textfile != 'none')) {
  28.     if (!isset($replace)) {
  29.         $replace = '';
  30.     }
  31.  
  32.     // Formats the data posted to this script
  33.     $textfile             = PMA_sqlAddslashes($textfile);
  34.     if (get_magic_quotes_gpc()) {
  35.         $field_terminater = stripslashes($field_terminater);
  36.         $enclosed         = PMA_sqlAddslashes(stripslashes($enclosed));
  37.         $escaped          = PMA_sqlAddslashes(stripslashes($escaped));
  38.         $line_terminator  = stripslashes($line_terminator);
  39.         $column_name      = PMA_sqlAddslashes(stripslashes($column_name));
  40.     } else {
  41.         $enclosed         = PMA_sqlAddslashes($enclosed);
  42.         $escaped          = PMA_sqlAddslashes($escaped);
  43.         $column_name      = PMA_sqlAddslashes($column_name);
  44.     }
  45.     
  46.     // Builds the query
  47.     $query     = 'LOAD DATA LOCAL INFILE \'' . $textfile . '\'';
  48.     if (!empty($replace)) {
  49.         $query .= ' ' . $replace;
  50.     }
  51.     $query     .= ' INTO TABLE ' . PMA_backquote($into_table);
  52.     if (isset($field_terminater)) {
  53.         $query .= ' FIELDS TERMINATED BY \'' . $field_terminater . '\'';
  54.     }
  55.     if (isset($enclose_option) && strlen($enclose_option) > 0) {
  56.         $query .= ' OPTIONALLY';
  57.     }
  58.     if (strlen($enclosed) > 0) {
  59.         $query .= ' ENCLOSED BY \'' . $enclosed . '\'';
  60.     }
  61.     if (strlen($escaped) > 0) {
  62.         $query .= ' ESCAPED BY \'' . $escaped . '\'';
  63.     }
  64.     if (strlen($line_terminator) > 0){
  65.         $query .= ' LINES TERMINATED BY \'' . $line_terminator . '\'';
  66.     }
  67.     if (strlen($column_name) > 0) {
  68.         if (PMA_MYSQL_INT_VERSION >= 32306) {
  69.             $query .= ' (';
  70.             $tmp   = split(',( ?)', $column_name);
  71.             for ($i = 0; $i < count($tmp); $i++) {
  72.                 if ($i > 0) {
  73.                     $query .= ', ';
  74.                 }
  75.                 $query     .= PMA_backquote(trim($tmp[$i]));
  76.             } // end for
  77.             $query .= ')';
  78.         } else {
  79.             $query .= ' (' . $column_name . ')';
  80.         }
  81.     }
  82.  
  83.     // Executes the query
  84.     // sql.php will stripslash the query if 'magic_quotes_gpc' is set to on
  85.     if (get_magic_quotes_gpc()) {
  86.         $sql_query = addslashes($query);
  87.     } else {
  88.         $sql_query = $query;
  89.     }
  90.     include('./sql.php');
  91. }
  92.  
  93.  
  94. /**
  95.  * The form used to define the query hasn't been yet submitted -> loads it
  96.  */
  97. else {
  98.     include('./ldi_table.php');
  99. }
  100. ?>
  101.