Jump to content

LOAD DATA INFILE ERROR


candice

Recommended Posts

Hi all, I am importing a csv file into my sql database and I am currently using the LOAD data infile function. However, it doesnt seem to detect the location of the file even though i have specified it in the query. Can anybody help? Attached below are my codes:

 

<?php 
session_start();
echo $name;
ob_start();
?>

<?php require_once('connection.php'); ?>

<?php 

//UPLOADING FILE
if(isset($_POST['upload']))
{

$uploaddir = 'C:\wamp\www\New admin Site/uploads/';

$uploadfile = $uploaddir . basename($_FILES['fileupload']['name']);

$file = array($uploadfile);//store the file into an array

echo '<pre>';
if (move_uploaded_file($_FILES['fileupload']['tmp_name'], $uploadfile)) {
	echo "File is valid, and was successfully uploaded.\n";
} else {
	echo "Possible file upload attack!\n";
}

echo 'Here is some more debugging info:';
print_r($_FILES);

print "</pre>";
}


  $fcontents = $_SESSION[csvfile]; 
  
  for($i=0; $i<sizeof($fcontents); $i++) { 
  
      $line = trim($fcontents[$i]); 
      $arr = explode("\t", $line); 
  
echo $arr."<br>\n";


}

//ATTRIBUTES
$fieldseparator = ',';
$lineseparator = '\n';

//READING OF FILE
$csvfile = $uploaddir . basename($_FILES['fileupload']['name']);

//TRUNCATE THE FILE BEFORE INSERTING IT INTO THE DATABASE
mysql_select_db($database, $test);
mysql_query("TRUNCATE TABLE timetable") or die("MySQL Error: " . mysql_error()); //Delete the existing rows

//IMPORT CSV INTO DATABASE
$lines = 0;
$queries = "";
$linearray = array();
$fcontents = file($csvfile); 

for($i=0; $i<sizeof($fcontents); $i++) { 

$lines++;

$line = trim($fcontents[$i]); 

$linearray = explode(',',$line);

$linemysql = implode("','",$linearray); // convert the array to a string

echo "$linemysql". "\n";

//$query = "INSERT INTO timetable values('$linemysql')";//Insert query to insert values into the database
$query = 'LOAD DATA INFILE "C:\wamp\www\New admin Site\uploads\testing.csv"
INTO TABLE timetable 
FIELDS TERMINATED BY ","
OPTIONALLY ENCLOSED BY """"
LINES TERMINATED BY "\r\n"';

mysql_query($query, $test) or die('SQL ERROR:'.mysql_error()); //Insert in the new values into the database

}

?>

</head>
<body>
</body>
</html>
<?php ob_flush(); ?>

Link to comment
https://forums.phpfreaks.com/topic/123801-load-data-infile-error/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.