Hi all,
I have a problem:
I must insert data in some tables loading them from a file .csv.
I have tried to add a query PHP: LOAD LOCAL INFILE but this tries the file on the server and not on connected user hard.
[codebox]global $conn;
$CSVFile_temp ="C:\\\queryrete\\\inviadati\\\anagrafica.csv";
$param = "LOAD DATA LOCAL INFILE '".$CSVFile."' INTO TABLE anagrafe ";
$param .= "FIELDS TERMINATED BY ',' ENCLOSED BY '\"' LINES TERMINATED BY '\\r\\n' IGNORE 1 LINES";
$param .= "SET pa_ind = AES_ENCRYPT(pa_ind,'decritta')";
mysql_query($param) or die('Error loading data file. Contact support or try naming your file with at least 3 characters (eg. 123.csv)
' . mysql_error());
[/codebox]
this code don't load the csv file.
I have transfered csv file into a httdocs folder and modified code:
[codebox]// Put your code here.
echo "Your message";
global $conn;
$temp = getcwd();
echo $temp;
$CSVFile_temp = $temp."/files/"."anagrafica.csv";
$CSVFile = str_replace("\\", "/" , $CSVFile_temp);
$param = "LOAD DATA LOCAL INFILE '".$CSVFile."' REPLACE INTO TABLE anagrafe ";
$param .= " FIELDS TERMINATED BY '\,' ENCLOSED BY '\"' LINES TERMINATED BY '\\r\\n' ";
$param .= " SET pa_ind = AES_ENCRYPT(PA_IND,'trappola')";
echo $param;
mysql_query($param) or die('Error loading data file.
' . mysql_error());
[/codebox]
This work bat a web user can upload file in a web folder?
Then I have used import csv funcion, that works very well,
[codebox]// Put your code here.
echo "Your message";
global $conn;
$temp = getcwd();
echo $temp;
$CSVFile_temp = $temp."/files/"."anagrafica.csv";
$CSVFile = str_replace("\\", "/" , $CSVFile_temp);
$param = "LOAD DATA LOCAL INFILE '".$CSVFile."' REPLACE INTO TABLE anagrafe ";
$param .= " FIELDS TERMINATED BY '\,' ENCLOSED BY '\"' LINES TERMINATED BY '\\r\\n' ";
$param .= " SET pa_ind = AES_ENCRYPT(PA_IND,'trappola')";
echo $param;
mysql_query($param) or die('Error loading data file.
' . mysql_error());
[/codebox]
but would have to insert some fields calculated in the columns. Is possible to insert calculate fields? How?
thanks