PHP Classes

File: cli.php

Recommend this page to a friend!
  Classes of Moisés Lima   PHP Import CSV to PostgreSQL   cli.php   Download  
File: cli.php
Role: Example script
Content type: text/plain
Description: Example script
Class: PHP Import CSV to PostgreSQL
Insert CSV file data into a PostgreSQL table
Author: By
Last change:
Date: 10 months ago
Size: 716 bytes
 

Contents

Class file image Download
#!/usr/bin/php -q
<?php

require_once 'vendor/autoload.php';

use
TheMoiza\Csvtopostgresql\CsvToPgsql;

$csvToPgsql = new CsvToPgsql;

$csvToPgsql->setConfigs([
   
'createPkey' => true,
   
'enableTrim' => true,
   
'enableTransaction' => true,
   
'justCreateTables' => false,
   
'inputEncoding' => 'UTF-8',
   
'outputEncoding' => 'UTF-8'
]);

print
'Wait...'.PHP_EOL;

$result = $csvToPgsql->convertCsvFromZip(
   
'csv_example.zip',
    [
       
"DB_HOST" => "127.0.0.1",
       
"DB_PORT" => "5432",
       
"DB_DATABASE" => "csvtopostgresql",
       
"DB_USERNAME" => "csvtopostgresql",
       
"DB_PASSWORD" => "csvtopostgresql",
       
"DB_SCHEMA" => "target_schema"
   
]
);

print (
$result['result'] ? 'Success' : 'Fail').PHP_EOL;

print
$result['message'].PHP_EOL;