you can try to implement and use your own class driver and pass the search path to PDO DriverOptions, for example. in symfony config:
A driver might look something like this:
namespace YourNamespace\YourBundle\Doctrine\DBAL\Driver\PDOPgSql; use Doctrine\DBAL\Platforms; class Driver extends \Doctrine\DBAL\Driver\PDOPgSql\Driver implements \Doctrine\DBAL\Driver { public function connect(array $params, $username = null, $password = null, array $driverOptions = array()) { // ADD SOME ERROR HANDLING WHEN THE SEARCH_PATH IS MISSING... $searchPath = $driverOptions['search_path']; unset($driverOptions['search_path']); $connection = new \Doctrine\DBAL\Driver\PDOConnection( $this->_constructPdoDsn($params), $username, $password, $driverOptions ); $connection->exec("SET SEARCH_PATH TO {$searchPath};"); return $connection; } /** * Constructs the Postgres PDO DSN. * * @return string The DSN. */ protected function _constructPdoDsn(array $params) { $dsn = 'pgsql:'; if (isset($params['host']) && $params['host'] != '') { $dsn .= 'host=' . $params['host'] . ' '; } if (isset($params['port']) && $params['port'] != '') { $dsn .= 'port=' . $params['port'] . ' '; } if (isset($params['dbname'])) { $dsn .= 'dbname=' . $params['dbname'] . ' '; } return $dsn; } }
You need the _constructPdoDsn method, because it is not defined as protected in \ Doctrine \ DBAL \ Driver \ PDOPgSql \ Driver. This is a βhackedβ bit because we use PDO DriverOptions, and I'm not sure if this is a good way, but it works.
Hope this helps.
Yours faithfully,
Patryk
Patryk kordylewski
source share