Symfony2 Doctrine run SQL from a file in CLI

2019-06-17 02:23发布

问题:

I can use this to execute SQL at the CLI

php app/console doctrine:query:sql "SELECT * FROM table"

But how can I use the same command to exec SQL from a file? E.g.

php app/console doctrine:query:sql filename.sql

I have tried > and < in various ways and cat but nothing even comes close to doing what I want.

I realised I can use straight mysql to do this, but I wish to do it via doctrine.

回答1:

php app/console doctrine:query:sql "$(< filename.sql)"


回答2:

With a current Symfony/Doctrine version you can easily run:

php bin/console doctrine:database:import [files]