Search code examples
symfony1database-connection

Symfony database connection without using database.yml


Let's say you have a situation where your Symfony application cannot get its database connection information from the databases.yml file.

In this situation, how can you set up a database connection "by hand" (let's assume Doctrine as the ORM)?


Solution

  • Maybe use "Opening New Connections"

    // bootstrap.php
    
    // ...
    $dsn = 'mysql:dbname=testdb;host=127.0.0.1';
    $user = 'dbuser';
    $password = 'dbpass';
    
    $dbh = new PDO($dsn, $user, $password);
    $conn = Doctrine_Manager::connection($dbh);
    

    Check as well those SO answers: