Thinkphp Connecting two libraries

Source: Internet
Author: User
Tags db2 dsn

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-&GT;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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.