New api/user.php
<?php/** * Created by Phpstorm. * User:administrator * DATE:2018/8/25 * time:15:20 */namespace app\api\controller;use think\Db;class User{public $d B2; Public Function __construct () {//Method One: Table prefix is not used//$this->DB2 = Db::connect ([////database type ' Type ' = ' mysql ',/////Database connection DSN configuration//' DSN ' = ', '/////server address// ' hostname ' + ' 127.0.0.1 ',////Database name//' databases ' + ' on ', '/////database user name ' username ' + ' root ',////Database Password//' password ' + ' root ',////Database connection port ' Hostport ' + ' 3306 ',////database connection parameters//' params ' = [],////Database encoding default Using UTF8//' charset ' = ' utf8 ',/////database table prefix//' prefix ' + ' o2o_ ',//]); } public Function Index () {echo ' Api/user '; Echo ' <br> '; $res = db (' sHop_station ')->find (1); $res = db (' ship_station ')->find (49); Dump ($res); Echo ' <br> '; Method One: The table prefix is not used//$ret = $this->db2->table (' o2o_shop_station ')->find (1); Method Two: Table prefixes are not used $db 2 = db::connect (' Mysql://root:[email protected]:3306/o2o#utf8 '); $ret = $db 2->table (' o2o_shop_station ')->find (1); Dump ($ret); }}
Datebase.php is still a normal configuration library one
// 服务器地址 ‘hostname‘ => ‘127.0.0.2‘, // 数据库名 ‘database‘ => ‘o2o‘, // 用户名 ‘username‘ => ‘root2‘, // 密码 ‘password‘ => ‘root2‘, // 端口 ‘hostport‘ => ‘3306‘, // 数据库表前缀 ‘prefix‘ => ‘o2o_‘,
Thinkphp Connecting two libraries