Compare Csv File Records To Database Table Records

Hello all,

I want to compare if the table already has a record with the same name as in the csv file, if it has already the record it just simply updates it…


$cols = str_getcsv($line, ';', '"');//csv file

 $fields = ImportationDetail::model()->findAll();

$modelA = $modelApp::model()->findByAttributes(array($fields[] => $cols[]));


 if (!$model)

$model = new $args[0];

But im getting this error


Illegal offset type

$modelA = $modelApp::model()->findByAttributes(array($fields[] => $cols[]));

Can you help to compare the two objects?

After this i want to insert the values onto database, something like this:


$model-> name = $cols[0];

$model-> description = $cols[1];

$model-> baseline = $cols[2];



But i dont want to write the table fields…because it might be other file to another table and the fields would be incorrect…

are you sure it’s a right way array($fields[] => $cols[]) ?

i mean i have syntax error in 5.5 at all


<?php

$f[1]='c1';

$f[2]='c2';

$c[1]=1;

$c[2]=2;


$ar = array($f[] => $c[]);  // ( ! ) Fatal error: Cannot use [] for reading in


var_dump($ar);





   

$fields = array();

$fields[] = $modelField->field;