thinkphp 串連兩個庫

來源:互聯網
上載者:User

標籤:hostname   user   space   dex   password   ble   public   names   database   

建立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 $db2;    public function __construct()    {        //方法一:表首碼沒有用        // $this->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 ‘<br>‘;        $res = db(‘shop_station‘)->find(1);        // $res = db(‘ship_station‘)->find(49);        dump($res);        echo ‘<br>‘;        //方法一:表首碼沒有用        // $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裡還是正常配置庫一
 // 伺服器位址       ‘hostname‘        => ‘127.0.0.2‘,       // 資料庫名       ‘database‘        => ‘o2o‘,       // 使用者名稱       ‘username‘        => ‘root2‘,       // 密碼       ‘password‘        => ‘root2‘,       // 連接埠       ‘hostport‘        => ‘3306‘,           // 資料庫表首碼       ‘prefix‘          => ‘o2o_‘,

thinkphp 串連兩個庫

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.