I need to import some csv files to mysql.
I recently found about the LOAD DATA INFILE, I checked the manual, as far as I understand, to imports each line of .csv file to the database.
I was wondering if there's an option to concatenate an extra value to what the csv file contains.
For example: my table has 3 columns.
MYTABLE(#name,#email,company_adrs);
The csv file has data for "name,email" only, and I have the address in a php variable.
With a normal loop, I would achieve this as follows:
//open file
while (/* not end of file, read eachline*/)
{
$current_line_of_csv_file; // contains: "John,john@john.com" without the 3rd column
$myAddrsVar= mysqli_real_escape_string($db, $_POST['adrs']); //"44 company st"
$insert = $db->query("INSERT MYTABLE (name,email,company_adrs) VALUES ( $current_line_of_csv_file,'".$myAddrsVar."')");
}
With this method I have to loop through each line the csv and do a query in each iteration.
I was wondering if LOAD DATA INFILE has a method to concatenate my data to the csv file? if so, how can I achieve it?
Thanks in advance