如何在Cakephp 2.x中获取当前的数据库连接名称

时间:2017-06-06 06:53:40

标签: cakephp

我的database.php中有两个(默认和测试)数据库连接:

public function __construct() {
        $this->default = array(
            'datasource' => 'Database/Mysql',
            'driver' => 'mysql',
                'persistent' => false,
                'encoding' => 'utf8',
                'prefix' => 'shaufel_',
                'host' => 'localhost',
                'database' => 'db',
                'login' => 'root', /*** replace this ***/
                'password' => 'root', /*** replace this ***/
        );

        //test db
        $this->test = $this->default;
        $this->test['database'] = $this->test['database'].'_test';
    }

如何在我的模型中获取当前数据库连接NAME?这意味着例如:if(current_db is testDB) do something。我使用Cakephp 2.9.7。

1 个答案:

答案 0 :(得分:1)

我自己找到了它:[ { "docId": "58d8f38cd2f554fdfca4fd18", "__v": 8, "clinicDetails": { "5908e342236dee7e7364698e": { "appointmentSlots": { "sat": { "5908e342236dee7e73646a44": { "bookFlag": true, "endTime": "07:00PM", "startTime": "06:30PM" }, "5908e342236dee7e73646a43": { "bookFlag": true, "endTime": "06:30PM", "startTime": "06:00PM" }, .......