Ok, here is what I'm trying to do.
I have a php script that needs to read files in a directory and import them into a MySQL table. I have pasted the code I have so far below.
The function builds the correct SQL statement but doesn't execute it correctly. My guess is that I'm not actually connecting to the file itself. Just displaying the name. Any help is greatly appreciated.
Paul
function dir2() {
$linkID = @mysql_connect("localhost","*","*");
@mysql_select_db("test", $linkID);
echo "Function dir2<br>\n";
$path = "/test";
If ($handle = opendir($path)) {
echo "Directory handle: $handle\n";
echo "Files: \n";
while (false !== ($file = readdir($handle))) {
if($file != "." && $file != "..") {
$findme = ".csv";
$pos1 = strpos($file, $findme);
If ($pos1 > 0) {
$filename = $path . "/" . $file;
$fileinfo = file_get_contents($filename);
$querystring = "LOAD DATA INFILE '$filename' in TABLE 'districtinfo' FIELDS TERMINATED by ',' ENCLOSED by '\"' ESCAPED by '\\\\' LINES TERMINATED by '\\r'";
print $querystring;
$result = @mysql_query($querystring,$linkID);
print "<br>Result = $result<br>";
// echo "<------- $file<br>\n";
}
}
}
closedir($handle);
@mysql_close($linkID);
}