PHP code example of urukalo / csvimporter

1. Go to this page and download the library: Download urukalo/csvimporter 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/ */

    

urukalo / csvimporter example snippets


        $connection = new PDO('mysql:host=127.0.0.1;dbname=my_db;charset=utf8', 'my_user', 'my_pass', array(
            PDO::ATTR_PERSISTENT => true
        ));
        
        $csvPath = __DIR__."/csv/";
        $importer = new csvImporter($connection, $csvPath);

        $configs = [

            [
                'table' => 'table_name',
                'fields' => [
                    'CSV_ID' => 'table_id',
                    'CreatedDate' => 'created_at',
                    'ModifiedDate' => 'updated_at',
                    'Website' => 'website',
                    'FaceBook' => 'facebook',
                    'Twitter' => 'twitter',
                    'Instagram' => 'instagram',
                    'ModifiedBy' => 'modified_by',
                    'Enabled' => 'enabled'
                ],
                'file' => 'file_name.csv',
            ]
        ];
        
         echo $importer->run($configs);