leomarquine / php-etl

Extract, Transform and Load data using PHP.
MIT License
178 stars 81 forks source link

Uncaught PDOException: SQLSTATE[HY093] #1

Closed nasrithamer closed 7 years ago

nasrithamer commented 7 years ago

I have a csv file i configured the leomarquine php-etl but in the process i have this error Fatal error: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined in C:\xampp\htdocs\etl\vendor\marquine\php-etl\src\Loaders\Table.php:162

when i saw the Table.php:162 i found the error in the execute function of PDO

the function of insert in the Class Table is :

protected function insert($items) {
    if (empty($items)) {
        return;
    }

    $statement = Etl::database($this->connection)->prepareInsert(
            $this->table, $this->columns
    );
    $callback = function ($items) use ($statement) {
        foreach ($items as $item) {
            /* if ($this->timestamps) {
              $item['created_at'] = $this->time;
              $item['updated_at'] = $this->time;
              } */

           // i want to see what is in the $item value i have an array ;the value of this in the bottom ***
            var_dump($item);

            $statement->execute($item);
        }
        //die();
    };

    Etl::database($this->connection)->transaction(
            $items, $callback, $this->transaction
    );
}

*** output of var_dump($item) array(1) { ["COD_HEXC,TECH,ELIG_FTTB,REFR_NRO,GEST_INFR,TYP_LOGM,NB_LOGT,REFR_PM,NUMR_VOIE,SS_NUMR_VOIE,NOM_VOIE,COD_POST,VILL,COD_INSEE,DAT_PREM_COMM_ADRS,DAT_DERN_COMM_ADRS,DEBIT_NET_PREC,DEBIT_NET,SELF_INST,ZDV_id,NOM_DE_ZDV,REGION,TYPE_ZDV,NB_FYR_FIX,NB_FYR_THD,NB_FYR_ADSL,NB_FYR_MOB_MONO,NB_FYR_MOB_MULTI,NB_FYR_MOB_MULTI_THD,NB_FYR_MOB_MULTI_ADSL,NB_CLNT_NC,week,cohorte,secteur_vad,COURTIER,Non_commercialisable,type,etat,Date_Visite_Last,Date_Visite_Next,Date_Arrivee,MOIS_LIVRAISON,POSITION,idVendeur,id_polygons"]=> string(243) "62133227TS,FTTB,1,NA,NA,NA,1,NA,143,,"AVENUE DE LA REPUBLIQUE",62420,"BILLY MONTIGNY",62133,07/11/2016,07/11/2016,30,30Mo,0,89,"HENIN CARVIN",NORD-EST,"WAR ZONE THD",0,0,0,0,0,0,0,0,0,2016_S0,Heninois,CONNECT,,0,0,now(),now(),now()," "," ",0,0" } the error returned of the line 162 ( $statement->execute($item); )
Fatal error: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined in C:\xampp\htdocs\etl\vendor\marquine\php-etl\src\Loaders\Table.php:162 Stack trace:

0 C:\xampp\htdocs\etl\vendor\marquine\php-etl\src\Loaders\Table.php(162): PDOStatement->execute(Array)

1 [internal function]: Marquine\Etl\Loaders\Table->Marquine\Etl\Loaders{closure}(Array)

2 C:\xampp\htdocs\etl\vendor\marquine\php-etl\src\Database\Connection.php(141): call_user_func(Object(Closure), Array)

3 C:\xampp\htdocs\etl\vendor\marquine\php-etl\src\Loaders\Table.php(168): Marquine\Etl\Database\Connection->transaction(Array, Object(Closure), 100)

4 C:\xampp\htdocs\etl\vendor\marquine\php-etl\src\Loaders\Table.php(123): Marquine\Etl\Loaders\Table->insert(Array)

5 C:\xampp\htdocs\etl\vendor\marquine\php-etl\src\Job.php(95): Marquine\Etl\Loaders\Table->load('pvr_fdr_copie', Array)

6 C:\xampp\htdocs\etl\insert.php(150): Marquine\Etl\Job->load('table', 'pvr_fdr_copie')

7 {main}

thrown in C:\xampp\htdocs\etl\vendor\marquine\php-etl\src\Loaders\Table.php on line 162

NOTE : the SUM of columns is equal of values

leomarquine commented 7 years ago

It seems you are not using the right delimiter in the extract csv step.

Your item should look like:

$item = [
    'COD_HEXC' => '62133227TS',
    'TECH ' => 'FTTB',
    'ELIG_FTTB' => 1,
    // and so on
]

But right now it only has one key containing all columns and one value containing the entire row.

nasrithamer commented 7 years ago

the solution is in the delimiter in the csv file . we must pass it in the

$job = new Job;
$job->extract('csv', 'csv.csv', ['delimiter' => ','])
    ->load('table', 'pvr_fdr_copie');

and be carefull with your columns name it must be without " " .

leomarquine commented 7 years ago

Exactly, otherwise the extract step will use the default delimiter ;