Hi,
I know how to set the DB config for dev/production ... but what's the best way to set the connection dynamically in a request?
ie. on a production server I want to be able to set some requests to call the slave DB instead of the master (for all queries during that request)... how do I make the DB class use a particular config rather than the "active" one?
Thanks,
Bruce
Inside your db.php config file you can create as many definitions as you want, the ones in there are just a default, one for each environment.
So create a second entry called 'slave', and define your slave database in there.
When running a query, it depends a bit on what you use.
With standard DB calls, you can specify the database to connect to as parameter of the execute() method. In this case you use execute('slave');
With Model_Crud and ORM models, you define the database to use via static::$_connection.
If you don't specify anything, the database defined by the 'active' setting is used as a default.