home *** CD-ROM | disk | FTP | other *** search
/ Cricao de Sites - 650 Layouts Prontos / WebMasters.iso / Servidores / xampp-win32-1.6.7-installer.exe / phpMyAdmin / libraries / import / ldi.php < prev    next >
Encoding:
PHP Script  |  2008-06-23  |  3.6 KB  |  114 lines

  1. <?php
  2. /* vim: set expandtab sw=4 ts=4 sts=4: */
  3. /**
  4.  * CSV import plugin for phpMyAdmin
  5.  *
  6.  * @version $Id: ldi.php 11326 2008-06-17 21:32:48Z lem9 $
  7.  */
  8. if (! defined('PHPMYADMIN')) {
  9.     exit;
  10. }
  11.  
  12. /**
  13.  *
  14.  */
  15. if ($plugin_param !== 'table') {
  16.     return;
  17. }
  18.  
  19. if (isset($plugin_list)) {
  20.     if ($GLOBALS['cfg']['Import']['ldi_local_option'] == 'auto') {
  21.         $GLOBALS['cfg']['Import']['ldi_local_option'] = FALSE;
  22.  
  23.         if (PMA_MYSQL_INT_VERSION < 32349) {
  24.                 $GLOBALS['cfg']['Import']['ldi_local_option'] = TRUE;
  25.         }
  26.  
  27.         if (PMA_MYSQL_INT_VERSION > 40003) {
  28.             $result = PMA_DBI_try_query('SHOW VARIABLES LIKE \'local\\_infile\';');
  29.             if ($result != FALSE && PMA_DBI_num_rows($result) > 0) {
  30.                 $tmp = PMA_DBI_fetch_row($result);
  31.                 if ($tmp[1] == 'ON') {
  32.                     $GLOBALS['cfg']['Import']['ldi_local_option'] = TRUE;
  33.                 }
  34.             }
  35.             PMA_DBI_free_result($result);
  36.             unset($result);
  37.         }
  38.     }
  39.     $plugin_list['ldi'] = array(
  40.         'text' => 'strLDI',
  41.         'extension' => 'ldi', // This is nonsense, however we want to default to our parser for csv
  42.         'options' => array(
  43.             array('type' => 'bool', 'name' => 'replace', 'text' => 'strReplaceTable'),
  44.             array('type' => 'bool', 'name' => 'ignore', 'text' => 'strIgnoreDuplicates'),
  45.             array('type' => 'text', 'name' => 'terminated', 'text' => 'strFieldsTerminatedBy', 'size' => 2, 'len' => 2),
  46.             array('type' => 'text', 'name' => 'enclosed', 'text' => 'strFieldsEnclosedBy', 'size' => 2, 'len' => 2),
  47.             array('type' => 'text', 'name' => 'escaped', 'text' => 'strFieldsEscapedBy', 'size' => 2, 'len' => 2),
  48.             array('type' => 'text', 'name' => 'new_line', 'text' => 'strLinesTerminatedBy', 'size' => 2),
  49.             array('type' => 'text', 'name' => 'columns', 'text' => 'strColumnNames'),
  50.             array('type' => 'bool', 'name' => 'local_option', 'text' => 'strLDILocal'),
  51.             ),
  52.         'options_text' => 'strOptions',
  53.         );
  54.     /* We do not define function when plugin is just queried for information above */
  55.     return;
  56. }
  57.  
  58. if ($import_file == 'none' || $compression != 'none' || $charset_conversion) {
  59.     // We handle only some kind of data!
  60.     $message = $strInvalidLDIImport;
  61.     $show_error_header = TRUE;
  62.     $error = TRUE;
  63.     return;
  64. }
  65.  
  66. $sql = 'LOAD DATA';
  67. if (isset($ldi_local_option)) {
  68.     $sql .= ' LOCAL';
  69. }
  70. $sql .= ' INFILE \'' . PMA_sqlAddslashes($import_file) . '\'';
  71. if (isset($ldi_replace)) {
  72.     $sql .= ' REPLACE';
  73. } elseif (isset($ldi_ignore)) {
  74.     $sql .= ' IGNORE';
  75. }
  76. $sql .= ' INTO TABLE ' . PMA_backquote($table);
  77.  
  78. if (strlen($ldi_terminated) > 0) {
  79.     $sql .= ' FIELDS TERMINATED BY \'' . $ldi_terminated . '\'';
  80. }
  81. if (strlen($ldi_enclosed) > 0) {
  82.     $sql .= ' ENCLOSED BY \'' . PMA_sqlAddslashes($ldi_enclosed) . '\'';
  83. }
  84. if (strlen($ldi_escaped) > 0) {
  85.     $sql .= ' ESCAPED BY \'' . PMA_sqlAddslashes($ldi_escaped) . '\'';
  86. }
  87. if (strlen($ldi_new_line) > 0){
  88.     if ($ldi_new_line == 'auto') {
  89.         $ldi_new_line = PMA_whichCrlf() == "\n" ? '\n' : '\r\n';
  90.     }
  91.     $sql .= ' LINES TERMINATED BY \'' . $ldi_new_line . '\'';
  92. }
  93. if ($skip_queries > 0) {
  94.     $sql .= ' IGNORE ' . $skip_queries . ' LINES';
  95.     $skip_queries = 0;
  96. }
  97. if (strlen($ldi_columns) > 0) {
  98.     $sql .= ' (';
  99.     $tmp   = split(',( ?)', $ldi_columns);
  100.     $cnt_tmp = count($tmp);
  101.     for ($i = 0; $i < $cnt_tmp; $i++) {
  102.         if ($i > 0) {
  103.             $sql .= ', ';
  104.         }
  105.         $sql     .= PMA_backquote(trim($tmp[$i]));
  106.     } // end for
  107.     $sql .= ')';
  108. }
  109.  
  110. PMA_importRunQuery($sql, $sql);
  111. PMA_importRunQuery();
  112. $finished = TRUE;
  113. ?>
  114.