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