Skip to content

Transform (csv) file to (sql) insert statement. 🐘

License

Notifications You must be signed in to change notification settings

91ahmed/CsvtoSql

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

17 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

CsvtoSQL

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');

About

Transform (csv) file to (sql) insert statement. 🐘

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages