Symfony Database Connection (DBAL Module)
Database connection with DBAL module in Symfony
We can use Ecotone's Symfony integration to reuse Connections that are already defined in your Symfony Application.
Using existing Connections [Recommended]
Suppose we already defined connection in our "doctrine.yaml" file:
doctrine:
dbal:
# If this configuration is not present, then "default" is implicit config
connections:
default:
url: '%env(resolve:DATABASE_DSN)%'Then to use it as our Default Connection, we can use Service Context config:
final readonly class EcotoneConfiguration
{
#[ServiceContext]
public function dbalConfiguration()
{
return SymfonyConnectionReference::defaultConnection('default');
}
}Using Manager Registry
Configuring Dbal Module with Manager Registry allows to make your Entities work as a Ecotone's Aggregates.
Suppose we already defined connection in our "doctrine.yaml" file:
Then to use it as our Default Connection, we can use Service Context config:
Using DSN
If we don't have existing connection defined, we can make use of DSN directly
Last updated
Was this helpful?