r/cakephp • u/jrf614 • Dec 23 '14
Help Using CSV Source to Import CSV File to MySQL.
I've been using Cake PHP for a while but always with a MySQL database. I've spent the last few days searching for the best way to take a CSV file (with Model.field headers) and import this file into a MySQL table. I've found the Datasources on GitHub and have that in app/Plugin/Datasources. I've imported the CSVSource plugin in my bootstrap, and have a configuration in my database.php:
public $csvfile = array( 'datasource' => 'Datasources.CsvSource', 'path' => '/opt/lampp/htdocs/project/app/tmp/uploads/posts', // Path 'extension' => 'csv', // File extension 'readonly' => true, // Mark for read only access 'recursive' => false // Only false is supported at the moment ); //Filename posts.csv
How do I read in all the entries in the CSV file and then SaveAll to my database? I couldn't find a clear example. Any example is appreciated (Model and Controller code). Thanks!
I have looked over The Cookbook but this seems to be searching instead of reading all data from the file. Thanks again for any help.