There is so much wrong with your code it's hard to pick where to begin...
- Your directory path is not escaped.
- You do not have anything to tell you that the directory cannot be opened.
%handle is not a PHP variable, and it's the wrong variable besides.
$entry is just the filename, not the full path.
- there's no semicolon at the end of the
mysql_query() call.
- Your 'enclose' and 'escape' chars are both
", neither of which were escaped.
echo the query instead of running it to be sure it's formed correctly if it's not working.
- You never actually check to see if the query was successful.
- turn on error reporting, because you've got some glaring parse errors that should make this script fail before it even runs.
- and the ever-popular:
mysql_* functions are deprecated, you should be using PDO or MySQLi.
So this should probably work a:
<?php
error_reporting(E_ALL);
define('DEBUG', true);
$basedir = 'C:\\Documents and Settings\\Desktop\\CSV Files\\';
if ($handle = opendir($basedir)) {
while(false !== ($entry = readdir($handle))) {
$query = "LOAD DATA LOCAL INFILE $basedir$entry
INTO TABLE main_table
FIELDS
TERMINATED BY ','
OPTIONALLY ENCLOSED BY '\"'
ESCAPED BY '\\'
LINES TERMINATED BY '\r\n'
IGNORE 1 LINES");
if(DEBUG) { echo $query . "\n"; }
if(!mysql_query($query)) {
die('Query failed: ' . mysql_error());
}
}
} else {
echo "Could not open $basedir";
}
ESCAPED BYpart be'\\', by the way?