0
如何在cakephp中使用兩個數據庫編寫連接查詢。這是我的代碼,我想連接兩個數據庫連接,但我有一個單一的Db連接。如何在cakephp中使用「兩個數據庫」編寫連接查詢
<?php
namespace App\Controller;
use App\Controller\AppController;
use Cake\Datasource\ConnectionManager;
use src\Model\Table\classScheduleDbConnTable;
class TimeTableController extends AppController {
public function index() {
$jpDB = ConnectionManager::get('default');
$ClsDB = ConnectionManager::get('test');
$result = $ClsDB->execute('SELECT * FROM t_class_schedule')->fetchAll('assoc');
$data=array();
foreach ($result as $key => $value) {
$data[$key]['id'] = $value['id'];
$dates = date("Y-m-d", strtotime($value['classDate']));
$data[$key]['fromTime'] = $value['fromTime'];
$data[$key]['toTime'] = $value['toTime'];
$data[$key]['keyWord'] = $value['keyWord'];
$data[$key]['classDate'] = $dates;
}
$this->set('datas',$data);
}
}
你甚至不使用CakePHP的查詢生成器,因此,這似乎更像是有關任何DBMS問題你正在使用,即一個普通的SQL問題? ** HTTP://stackoverflow.com/questions/32033558/how-to-use-different-datasources-in-a-query-using-cakephp3** – ndm