Fairly simple question really, but is there any way at all, to get Doctrine (when using Symfony's console) to use a different database user than the ones provided in the parameters?
Edit
Was suggested I explain myself.
I have modified Symony2 to use 2 different MySQL users based on context 4 ways. I have two bundles, a Core and an Administration bundle. The modification is that the database user located in the Core bundle only needs Read access privileges to the database, while Administration also has reduced privileges, but can Insert, Update, and Delete records.
This is accomplished by using Symfony's regular expression based url matching (administration is a totally different URL, not just a /admin). So I have configurations for Development Environment on the two local url's, and for Production for the two local url's.
As mentioned, even administration has reduced privileges, entirely for security reasons. I do not want that database user to be able to alter tables or change schemas.
On Development environment, database users are given full privileges of course
Right now, when I run Doctrine Migrations and Schema updates on Production, I have to manually adjust the given database user elevated privileges and then revoke them while I do my business.
I would simply like the console version of doctrine to use a third user that has slightly more elevated privileges.
Yes - it may not be exactly what you're looking for, but you could have Doctrine connect to completely different databases, using different users, and on different hosts, depending on whether you're in the development or production environment.
To do so:
Open your config.yml
and locate this section
doctrine:
dbal:
# Remove from here
driver: "%database_driver%"
host: "%database_host%"
port: "%database_port%"
dbname: "%database_name%"
user: "%database_user%"
password: "%database_password%"
# Stop here
Delete the lines where I've marked in the comments. You'll want to keep the doctrine
and dbal
lines so other Doctrine settings are preserved in the lower lines.
Open config_dev.yml
and config_prod.yml
and add the following
doctrine:
dbal:
driver: "pdo_mysql"
host: "your_host_here (usually localhost)"
port: "3306"
dbname: "db_name_here"
user: "db_user_here"
password: "db_password_here"
Replace values appropriately for each file. Then you can run php app/console
commands using the --env=prod
and --env=dev
flags. You will also be connected to different databases when you use app.php
and app_dev.php
, respectively.