I'm sure I'm making some kind of mistake, but whatever suggested in the official Propel / symfony docs and even here in stackoverflow doesn't seem to work for me. Official docs should probably take better care of programmers who have little symfony experience.
Although we do not prefer to edit the core files of any framework / third-party libraries, but this forces me to edit the kernel files to make me a working solution. The solution that worked for me is the following:
database.yml My database.yml file looks like this:
all: propel: class: sfPropelDatabase param: classname: PropelPDO dsn: 'mysql:host=localhost;dbname=wzo;' username: testuserwzo password: encoding: utf8 persistent: true pooling: true slave: class: sfPropelDatabase param: classname: PropelPDO dsn: 'mysql:host=localhost;dbname=wzoslv;' username: testuserwzoslv password: encoding: utf8 persistent: true pooling: true
After that I edited the Propel.php file as follows
For Propel 1.4
File: lib / vendor / symfony / lib / plugins / sfPropelPlugin / lib / vendor / propel / Propel.php
Change line 542-543
// we've already ensured that the configuration exists, in previous if-statement $slaveconfigs = isset(self::$configuration['datasources'][$name]['slaves']) ? self::$configuration['datasources'][$name]['slaves'] : null;
c (added one line between them)
// we've already ensured that the configuration exists, in previous if-statement self::$configuration['datasources'][$name]['slaves'] = isset(self::$configuration['datasources']['slave']) ? self::$configuration['datasources']['slave'] : null; $slaveconfigs = isset(self::$configuration['datasources'][$name]['slaves']) ? self::$configuration['datasources'][$name]['slaves'] : null;
Then in the same file, line 560 changed
$con = Propel::initConnection($conparams, $name);
to
$con = Propel::initConnection($conparams, 'slave');
For propeller 1.6 (We upgraded the engine just to make it work, but went back to propel 1.4 later, as the upgrade in production should be well tested.)
File: plugins / sfPropelORMPlugin / lib / vendor / propel / runtime / lib / Propel.php
Modified line 601
$slaveconfigs = isset(self::$configuration['datasources'][$name]['slaves']) ? self::$configuration['datasources'][$name]['slaves'] : null;
to (added one line earlier)
self::$configuration['datasources'][$name]['slaves'] = isset(self::$configuration['datasources']['slave']) ? self::$configuration['datasources']['slave'] : null; $slaveconfigs = isset(self::$configuration['datasources'][$name]['slaves']) ? self::$configuration['datasources'][$name]['slaves'] : null;
Then in the same file, line 629 changed
$con = Propel::initConnection($conparams, $name);
to
$con = Propel::initConnection($conparams, 'slave');
Then the following test file gave the expected result
class kapsActions extends sfActions { public function executeIndex(sfWebRequest $request) { $con_write = Propel::getConnection(OddPlayPeer::DATABASE_NAME, Propel::CONNECTION_WRITE); $con_read = Propel::getConnection(OddPlayPeer::DATABASE_NAME, Propel::CONNECTION_READ); $oddPlay = OddPlayPeer::retrieveByPK(28,0,$con_write); echo "on write connection, result=".$oddPlay->getResult().$oddPlay->getPlayscore(); $oddPlayRead = OddPlayPeer::retrieveByPK(27,0,$con_read); echo "<br/>on Read connection, result=".$oddPlayRead->getResult().$oddPlayRead->getPlayscore(); exit;
I still do not recommend editing the main files, but this solution worked for us as if in disrepair. Someone else, if necessary, can use it in disrepair . Still looking for the perfect solution.