PHP code example of wizaplace / php-etl

1. Go to this page and download the library: Download wizaplace/php-etl library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

wizaplace / php-etl example snippets


use Wizaplace\Etl\Etl;
use Wizaplace\Etl\Extractors\Csv;
use Wizaplace\Etl\Transformers\Trim;
use Wizaplace\Etl\Loaders\Insert;
use Wizaplace\Etl\Database\Manager;
use Wizaplace\Etl\Database\ConnectionFactory;

// Get your database settings :
$config = [
    'driver'    => 'mysql',
    'host'      => 'localhost',
    'port'      => '3306',
    'database'  => 'myDatabase',
    'username'  => 'foo',
    'password'  => 'bar',
    'charset'   => 'utf8',
    'collation' => 'utf8_unicode_ci',
];

// Instanciate all the components (manually or automatically with DI)
$manager = new Manager(new ConnectionFactory());
$manager->addConnection($config);
$etl = new Etl();
$extractor = new Csv();
$transformer = new Trim();
$loader = new Insert($manager);

$etl->extract($extractor, '/path/to/users.csv')
    ->transform(
        $transformer,
        [Step::COLUMNS => ['name', 'email']]
    )
    ->load($loader, 'users')
    ->run();
shell
composer