the folders structure of my site is the following: www.mysite.it/site/scripts.
At this path there are two files: import.php and tabella.csv.
tabella.csv is a CSV file like this:
"2016-09-02", 100.01, 4005.09, 5000, 1.09, 120.09, 100.5, 200.77
"2016-09-03", 150.01, 4205.09, 5600, 1.10, 150.09, 300.5,300.77
import.php is the PHP script to execute te import and it's a file like this:
<?php
$csvFile = "../scripts/tabella.csv";
$db = @mysql_connect('****', '****', '****');
@mysql_select_db('******');
$query = 'LOAD DATA LOCAL INFILE \' '. $csvFile .' \' INTO TABLE rame
FIELDS TERMINATED BY \',\'
LINES TERMINATED BY \'
\'
IGNORE 1 LINES
(
giorno,
lmedollton,
changedolleuro,
euroton,
lmesterton,
delnotiz,
girm,
sgm
)';
if(!mysql_query($query)){
die(mysql_error());
}
mysql_close($db);
?>
The error is 'file not found': I tried to use 'tabella.csv' and the the realpath also (using realpath PHP function) but the error is always the same. Which is the correct string that I have to assign to $csvFile variable? Can you help me, please?
You should provide an absolute path to your csv file e.g.
$csvFile = "/var/www/htdocs/site/scripts/tabella.csv"
because mysql will not be able to resolve the path relative to apache httpdoc-root directory. See also the Mysql-Doc:
If LOCAL is specified, the file is read by the client program on the client host and sent to the server. The file can be given as a full path name to specify its exact location. If given as a relative path name, the name is interpreted relative to the directory in which the client program was started.