Thinkphp 5は2つのライブラリを同時に接続する
2264 ワード
新しいapi/user.php
datebase.phpでは通常の構成ライブラリ1です
転載先:https://www.cnblogs.com/haima/p/9556154.html
db2 = Db::connect([
// //
// 'type' => 'mysql',
// // DSN
// 'dsn' => '',
// //
// 'hostname' => '127.0.0.1',
// //
// 'database' => 'o2o',
// //
// 'username' => 'root',
// //
// 'password' => 'root',
// //
// 'hostport' => '3306',
// //
// 'params' => [],
// // utf8
// 'charset' => 'utf8',
// //
// 'prefix' => 'o2o_',
// ]);
}
public function index()
{
echo 'api/User';
echo '
';
$res = db('shop_station')->find(1);
// $res = db('ship_station')->find(49);
dump($res);
echo '
';
// :
// $ret = $this->db2->table('o2o_shop_station')->find(1);
// :
$db2 = Db::connect('mysql://root:[email protected]:3306/o2o#utf8');
$ret = $db2->table('o2o_shop_station')->find(1);
dump($ret);
}
}
datebase.phpでは通常の構成ライブラリ1です
//
'hostname' => '127.0.0.2',
//
'database' => 'o2o',
//
'username' => 'root2',
//
'password' => 'root2',
//
'hostport' => '3306',
//
'prefix' => 'o2o_',
転載先:https://www.cnblogs.com/haima/p/9556154.html