csv / csvtosql
PHP class to extract data from (csv) file and transform it to (sql) file as insert statement.
1.0.0
2023-02-06 05:57 UTC
This package is auto-updated.
Last update: 2024-09-12 09:18:45 UTC
README
PHP class to extract data from (csv) file and transform it to (sql) insert statement.
Install
via composer
composer require csv/csvtosql
Example
// 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)
Methods Description
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');