Symfony控制器:当前使用哪个数据库驱动程序?

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(/* … */);
}

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

Ref this