PHP version 4.2.x is 402xx
[phpmyadmin/crack.git] / ldi_check.php3
bloba536b229e2ed18a53a8dbeecce6a501d241c591b
1 <?php
2 /* $Id$ */
3 // vim: expandtab sw=4 ts=4 sts=4:
6 /**
7 * This file checks and builds the sql-string for
8 * LOAD DATA INFILE 'file_name.txt' [REPLACE | IGNORE] INTO TABLE table_name
9 * [FIELDS
10 * [TERMINATED BY '\t']
11 * [OPTIONALLY] ENCLOSED BY "]
12 * [ESCAPED BY '\\' ]]
13 * [LINES TERMINATED BY '\n']
14 * [(column_name,...)]
18 /**
19 * Gets some core scripts
21 require('./libraries/grab_globals.lib.php3');
22 require('./libraries/common.lib.php3');
25 /**
26 * The form used to define the query has been submitted -> do the work
28 if (isset($btnLDI) && ($textfile != 'none')) {
29 if (!isset($replace)) {
30 $replace = '';
33 error_reporting(E_ALL);
34 chmod($textfile, 0644);
36 // Kanji encoding convert appended by Y.Kawada
37 if (function_exists('PMA_kanji_file_conv')) {
38 $textfile = PMA_kanji_file_conv($textfile, $knjenc, isset($xkana) ? $xkana : '');
41 // Convert the file's charset if necessary
42 if ($cfg['AllowAnywhereRecoding'] && $allow_recoding
43 && isset($charset_of_file) && $charset_of_file != $charset) {
44 $textfile = PMA_convert_file($charset_of_file, $convcharset, $textfile);
47 // Formats the data posted to this script
48 $textfile = PMA_sqlAddslashes($textfile);
49 if (get_magic_quotes_gpc()) {
50 $field_terminater = stripslashes($field_terminater);
51 $enclosed = PMA_sqlAddslashes(stripslashes($enclosed));
52 $escaped = PMA_sqlAddslashes(stripslashes($escaped));
53 $line_terminator = stripslashes($line_terminator);
54 $column_name = PMA_sqlAddslashes(stripslashes($column_name));
55 } else {
56 $enclosed = PMA_sqlAddslashes($enclosed);
57 $escaped = PMA_sqlAddslashes($escaped);
58 $column_name = PMA_sqlAddslashes($column_name);
61 // Builds the query
62 $query = 'LOAD DATA LOCAL INFILE \'' . $textfile . '\'';
63 if (!empty($replace)) {
64 $query .= ' ' . $replace;
66 $query .= ' INTO TABLE ' . PMA_backquote($into_table);
67 if (isset($field_terminater)) {
68 $query .= ' FIELDS TERMINATED BY \'' . $field_terminater . '\'';
70 if (isset($enclose_option) && strlen($enclose_option) > 0) {
71 $query .= ' OPTIONALLY';
73 if (strlen($enclosed) > 0) {
74 $query .= ' ENCLOSED BY \'' . $enclosed . '\'';
76 if (strlen($escaped) > 0) {
77 $query .= ' ESCAPED BY \'' . $escaped . '\'';
79 if (strlen($line_terminator) > 0){
80 $query .= ' LINES TERMINATED BY \'' . $line_terminator . '\'';
82 if (strlen($column_name) > 0) {
83 if (PMA_MYSQL_INT_VERSION >= 32306) {
84 $query .= ' (';
85 $tmp = split(',( ?)', $column_name);
86 for ($i = 0; $i < count($tmp); $i++) {
87 if ($i > 0) {
88 $query .= ', ';
90 $query .= PMA_backquote(trim($tmp[$i]));
91 } // end for
92 $query .= ')';
93 } else {
94 $query .= ' (' . $column_name . ')';
98 // Executes the query
99 // sql.php3 will stripslash the query if 'magic_quotes_gpc' is set to on
100 if (get_magic_quotes_gpc()) {
101 $sql_query = addslashes($query);
102 } else {
103 $sql_query = $query;
106 // We could rename the ldi* scripts to tbl_properties_ldi* to improve
107 // consistency with the other sub-pages.
109 // The $goto in ldi_table.php3 is set to tbl_properties.php3 but maybe
110 // if would be better to Browse the latest inserted data.
111 include('./sql.php3');
116 * The form used to define the query hasn't been yet submitted -> loads it
118 else {
119 include('./ldi_table.php3');