PHP class to extract data from (csv) file and transform it to (sql) insert statement.
via composer
composer require csv/csvtosql
// Import vendor autoload
require ('vendor/autoload.php');
// Example
$csv = new Csv\Csvtosql\TransformCsv();
$csv->file('files/sales.csv') // Source (csv file)
->table('salse')
->transform()
->exportSQL('transform/sales.sql'); // Destination (new sql file with insert statement)
1- file()
Determine the source csv file you need to transform.
// @param string (csv source file path)
file('folder/file.csv');
2- table()
Determine the name of the table you want to use in the sql statement. The class will consider the first row of the csv file as the columns of the table.
// @param string (table name)
table('tablename');
3- transform()
Extract data from (csv) and Transform it to (sql).
4- exportSQL()
Create a new (sql) file with the transformed data as an insert statement.
// @param string (new sql file destination)
exportSQL('exported/file.sql');