Reputation: 821
Hi I would like to know if there is a way to save a CSV file into a mysql table column using php? Please see that I am not seeking answers for importing/export data to & from table to csv file, I need to save the entire file after exporting from somewhere into a table. say for example:
id date file
1 8/16/2022 abc.csv
2 7/16/2022 xyz.csv
I have everything till the point of data insertion. Just need someone to guide me on how to insert the file into table column using php, am using codeigniter.
Upvotes: 0
Views: 230
Reputation: 1256
If I understand your question correctly, it should be fairly simple. Assuming you already have a PDO object called $dbh
, something similar to this should work (not verified):
$myStringContainingTheWholeFirstCsv = file_get_contents('abc.csv');
$sth = $dbh->prepare('INSERT INTO `my_table_name` (`my_column_name`) VALUES (:csv)');
$sth->bindParam(':csv', $myStringContainingTheWholeFirstCsv, PDO::PARAM_STR);
$sth->execute();
Upvotes: 2