(See my edit below for a better question) How do I control which connection is selected (from the right environment section in the database.yml) in a symfony1.4 task using just a generic Doctrine_Query::create()
to create the query?
I'm using a database.yml that looks something like this:
prod:
doctrine:
class: sfDoctrineDatabase
param:
dsn: mysql://some:pass@domain:port/database
log:
class: sfDoctrineDatabase
param:
dsn: mysql://some:pass@domain:port/database
auth:
class: sfDoctrineDatabase
param:
dsn: mysql://some:pass@domain:port/database
dev:
doctrine:
class: sfDoctrineDatabase
param:
dsn: mysql://some:otherpass@domain:port/database
log:
class: sfDoctrineDatabase
param:
dsn: mysql://some:otherpass@domain:port/database
auth:
class: sfDoctrineDatabase
param:
dsn: mysql://some:otherpass@domain:port/database
And I want to be able to control which one of those database definitions is used when calling something like:
$query = Doctrine_Query::create()
->select('*')
->from('Products p')
->where('p.id = ?', $productID)
->limit(1);
$OfpFlPr = $query->execute()->getFirst();
At the moment I'm not able to set the connection like so $query = Doctrine_Query::create($conn);
.
Any help would be greatly appreciated!
EDIT:
I have lots of code deeper in the software where Doctrine_Query::create()
is used (without the connection argument). It seems to select the right environment and connection through web requests. But I can't figure out how it does this, so I can make my CLI commands work the same way (they don't select the right connection and environment at the moment). That's why I need to know how to control which connection is 'automaticly' used (selected by default).
Question:
So I guess in conclusion my question would be:
How can I control which connection is selected by default in lower level code which uses Doctrine_Query::create()
while the code is being executed as a symfony CLI command?
prod
anddev
). Lets say (for the sake of the example) that the product table is available over theprod.auth
as well as thedev.auth
connection. – Tommy Bravoschema.yml
is spread over multiple databases in my set up. It can however exist in both environments. And for each environment it should exist under the same connection name. – Tommy Bravoconnection: doctrine
on Product,connection: log
on Log model. – Marek