0

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)?

1 Answer 1

3

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:

Sign up to request clarification or add additional context in comments.

2 Comments

But how do you cause this connection to be the default connection in the same manner as the connection information in databases.yml turns into the default connection for the rest of the application? Or does it become the default connection merely by running in bootstrap.php?
In fact, you "simply" want to override the default behavior (processing something else instead of databases.yml) ? Edited my answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.