Lumen
Lumen

Reputation: 3574

Symfony controller: Which database driver is currently being used?

In a Symfony controller’s action, how can I find out which database driver is currently being used? Something like

public function testAction(Request $request)
{
    // How to accomplish this?
    switch ($this->getDoctrine()->getDriverName()) {
        case 'pdo_mysql':
            // execute MySQL-specific query…
            break;
        case 'pdo_sqlite':
            // execute SQLite-specific query…
            break;
        default:
            // …
    }

    return $this->render(/* … */);
}

Upvotes: 1

Views: 774

Answers (1)

vijaykumar
vijaykumar

Reputation: 4806

You can use $this->getDoctrine()->getConnection( )->getDriver() The getConnection() will return object. You can access all their details in that object

Ref this

Upvotes: 5

Related Questions