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

Lum*_*men 1 php symfony

在Symfony控制器的操作中,如何找出当前使用的数据库驱动程序?就像是

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(/* … */);
}
Run Code Online (Sandbox Code Playgroud)

vij*_*mar 5

您可以使用$this->getDoctrine()->getConnection( )->getDriver() getConnection()将返回对象.您可以访问该对象中的所有详细信息

参考这个