Skip to content

Instantly share code, notes, and snippets.

@stajnert
Last active December 15, 2015 23:59
Show Gist options
  • Save stajnert/5344107 to your computer and use it in GitHub Desktop.
Save stajnert/5344107 to your computer and use it in GitHub Desktop.
Chane connection with db - symfony 1.4
<?php
// connect with other database
// $instance - object with new database data
new sfDoctrineDatabase(array(
'name' => 'instance',
'dsn' => 'mysql:host=' . $instance->getInstanceDbHost() . ';dbname=' . $instance->getInstanceDbName(),
'username' => $instance->getInstanceDbUser(),
'password' => $instance->getInstanceDbPassword(),
));
// do something with new db
// back to connection from database.yml
Doctrine_Manager::getInstance()->getCurrentConnection()->close();
$db = sfContext::getInstance()->getDatabaseManager()->getDatabase('doctrine');
$params = array(
$db->getParameter('dsn'),
$db->getParameter('username'),
$db->getParameter('password'),
'doctrine'
);
Doctrine_Manager::getInstance()->connection($params);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment