7

I'm working with symfony and I would like to know how I can do a simple insert using the doctrine:dql task.

./symfony doctrine:dql "<what should I put here?>"
greg0ire
  • 22,714
  • 16
  • 72
  • 101
  • I have a feeling you can only do SELECTs as only "FROM ..." seems to work and it implies there's a SELECT in front. Easiest alternative would probably be to run a specific fixture file which does the INSERT. – Tom Jun 22 '11 at 22:41
  • @Tom: you can also do UPDATE and DELETE requests whith this command. So why not DELETE requests? – greg0ire Jun 23 '11 at 05:22

2 Answers2

12

You officially cannot INSERT using DQL. Only SELECT, UPDATE and DELETE.

Yura
  • 2,690
  • 26
  • 32
  • 2
    Actually now you can: The \Doctrine\DBAL\Query\QueryBuilder supports building SELECT, INSERT, UPDATE and DELETE queries. https://www.doctrine-project.org/projects/doctrine-dbal/en/2.8/reference/query-builder.html – Simon Berton Oct 01 '18 at 14:56
  • 1
    @SimonBerton The link you provide is for the SQL Query Builder of the DBAL sub-project, not the DQL Query Builder. They are two unrelated query builders. – jlh Sep 07 '20 at 13:52
2

With Doctrine you don´t use INSERT´s. This type of query must be made by the Entity Manager, through its method PERSIST.

rikitikitik
  • 2,414
  • 2
  • 26
  • 37
Matt
  • 31
  • 1
  • I slightly modified the tags, the question was about doctrine 1.2 . But your answer could be interesting anyway... +1 – greg0ire Dec 19 '12 at 09:10