Prevent CakePHP from automatically connecting to database when instantiating model

后端 未结 2 1112
旧巷少年郎
旧巷少年郎 2021-02-11 02:40

The DBA at my company has a script that automatically kills long-running database connections and queries on our production databases. I\'ve written a CakePHP Shell application

2条回答
  •  暗喜
    暗喜 (楼主)
    2021-02-11 03:05

    Maybe you can manually connect/disconnect when you need to?

    DboSource has lots of methods for you to play with. Here's a list of functions that may be useful:

    $db = ConnectionManager::getDataSource('local');
    
    $isconnected = $db->isConnected();  //is the connection open?
    $db->close();  //close the connection
    $db->reconnect();  //reconnect to the db
    

    More methods are listed in the DboSource API docs

提交回复
热议问题