CakePHP 2.1.x - Run a query without any models in AppController

前端 未结 3 1379
臣服心动
臣服心动 2021-02-05 08:38

I am trying to run a query in AppController on a table that has no Model associated with it. I don\'t want to use a Model cause this query would fire on every request and I gues

3条回答
  •  無奈伤痛
    2021-02-05 09:31

    The getDataSource() method is static in CakePHP 2.x, so you should be able to use:

    $db = ConnectionManager::getDataSource('default');
    $db->rawQuery($some_sql);
    

提交回复
热议问题