Good morning all,
I am on a project under symfony4 ‘
I made an association membership management application.
Until now when I wanted to update my membership list with a csv file I did it directly in phpMyAdmin. I have a staging table which I called ‘import_csv’. I import my csv file on this table and thanks to two requests I add and update my membership list. But I would like to create an admin interface to do the same.
I managed to create the import management of my csv file on my intermediate table.
I would like to transcribe my SQL queries into my Symfony Controller and this is where I am blocking.
My first SQL query to add new members located on my table:
INSERT INTO adherent
(last_name,first_name,to_number,born)
SELECT
import_csv.last_name,import_csv.first_name,iimport_csv.to_number,import_csv.born
FROM import_csv LEFT JOIN adherent ON import_csv.to_number=adherent.to_number
WHERE adherent.to_number IS NULL
I tried a lot of things but I can’t do it:
/**
* @Route("import/insert", name="import_insert")
*/
public function import_insert(ObjectManager $manager)
{
$qb = $manager->createQueryBuilder();
$qb ->select('import_csv.last_name,import_csv.first_name,import_csv.to_number,import_csv.born')
->from('AppEntityImport_csv','i')
->leftjoin('AppEntityAdherent on i.to_number=a.to_number','a')
->where('a.to_number IS NULL');
$adherent = new AppEntityAdherent();
$manager->persist($adherent);
$manager->flush();
return $this->redirectToRoute('import_csv');
}
Thank you for any help you could give me.
2
Answers
I used a layer underlying the ORM, the DBAL (for Database Abstraction Layer) which allows among other things native queries.
It works. the database takes the value indicate but the return does not take place and I have this error: SQLSTATE[HY000]: General error
It’s good I found.
exec and no fetchAll