I would like to know if anyone has used the component mentioned in the title (Goodby / csv) for PHP, because I have a problem with it. I explain, I am developing an application that manages software licenses where users are loaded by csv files to a MySQL database and for that I want to contemplate that every time I upload a file with the students, each record (csv row) is checked for see if it exists in the BD and do not duplicate it. The problem is that the component seems to be making an implicit loop of all the sentences that are delimited (csv) and in that interval I can not check each row for that purpose. I pass the code to see if you can see it clearly.
This is one of the functions that are responsible for what was commented:
public function InsertarProfesores($ficheroTmp){
try{
$config = new LexerConfig();
$config
->setDelimiter(";") // Customize delimiter. Default value is comma(,)
->setEnclosure("'") // Customize enclosure. Default value is double quotation(")
->setEscape("\") // Customize escape character. Default value is backslash(\)
->setToCharset('UTF-8') // Customize target encoding. Default value is null, no converting.
;
$lexer = new Lexer($config);
$interpreter = new Interpreter();
$pdo = $this->pdo;
$interpreter->addObserver(function(array $columns) use ($pdo) {
$stmt = $pdo->prepare('INSERT INTO profesores (departamento,dni,nombre, primer_apellido, segundo_apellido,tlf_sms,direccion,email,num_afiliacion, tutor_de) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)');
$stmt->execute($columns);
});
$lexer->parse($ficheroTmp, $interpreter);
}catch(Exception $e){
die($e->getMessage());
}
}