PMA\libraries\Util::whichCrlf PHP Method

whichCrlf() public static method

Defines the value depending on the user OS.
public static whichCrlf ( ) : string
return string the value to use
    public static function whichCrlf()
    {
        // The 'PMA_USR_OS' constant is defined in "libraries/Config.php"
        // Win case
        if (PMA_USR_OS == 'Win') {
            $the_crlf = "\r\n";
        } else {
            // Others
            $the_crlf = "\n";
        }
        return $the_crlf;
    }

Usage Example

Example #1
0
 /**
  * Handles the whole import logic
  *
  * @param array &$sql_data 2-element array with sql data
  *
  * @return void
  */
 public function doImport(&$sql_data = array())
 {
     global $finished, $import_file, $compression, $charset_conversion, $table;
     global $ldi_local_option, $ldi_replace, $ldi_ignore, $ldi_terminated, $ldi_enclosed, $ldi_escaped, $ldi_new_line, $skip_queries, $ldi_columns;
     if ($import_file == 'none' || $compression != 'none' || $charset_conversion) {
         // We handle only some kind of data!
         $GLOBALS['message'] = PMA\libraries\Message::error(__('This plugin does not support compressed imports!'));
         $GLOBALS['error'] = true;
         return;
     }
     $sql = 'LOAD DATA';
     if (isset($ldi_local_option)) {
         $sql .= ' LOCAL';
     }
     $sql .= ' INFILE \'' . $GLOBALS['dbi']->escapeString($import_file) . '\'';
     if (isset($ldi_replace)) {
         $sql .= ' REPLACE';
     } elseif (isset($ldi_ignore)) {
         $sql .= ' IGNORE';
     }
     $sql .= ' INTO TABLE ' . PMA\libraries\Util::backquote($table);
     if (strlen($ldi_terminated) > 0) {
         $sql .= ' FIELDS TERMINATED BY \'' . $ldi_terminated . '\'';
     }
     if (strlen($ldi_enclosed) > 0) {
         $sql .= ' ENCLOSED BY \'' . $GLOBALS['dbi']->escapeString($ldi_enclosed) . '\'';
     }
     if (strlen($ldi_escaped) > 0) {
         $sql .= ' ESCAPED BY \'' . $GLOBALS['dbi']->escapeString($ldi_escaped) . '\'';
     }
     if (strlen($ldi_new_line) > 0) {
         if ($ldi_new_line == 'auto') {
             $ldi_new_line = PMA\libraries\Util::whichCrlf() == "\n" ? '\\n' : '\\r\\n';
         }
         $sql .= ' LINES TERMINATED BY \'' . $ldi_new_line . '\'';
     }
     if ($skip_queries > 0) {
         $sql .= ' IGNORE ' . $skip_queries . ' LINES';
         $skip_queries = 0;
     }
     if (strlen($ldi_columns) > 0) {
         $sql .= ' (';
         $tmp = preg_split('/,( ?)/', $ldi_columns);
         $cnt_tmp = count($tmp);
         for ($i = 0; $i < $cnt_tmp; $i++) {
             if ($i > 0) {
                 $sql .= ', ';
             }
             /* Trim also `, if user already included backquoted fields */
             $sql .= PMA\libraries\Util::backquote(trim($tmp[$i], " \t\r\n\v`"));
         }
         // end for
         $sql .= ')';
     }
     PMA_importRunQuery($sql, $sql, $sql_data);
     PMA_importRunQuery('', '', $sql_data);
     $finished = true;
 }
Util