zoukankan      html  css  js  c++  java
  • Thinkphp5多数据库切换

    在项目开发中需要Thinkphp5读取多个数据库的数据,本文详细介绍Thinkphp5多数据库切换

    一、在database.php配置默认数据库连接




    'type'           => 'mysql',
    'hostname'       => '服务器IP地址',
    'database'       => '数据库名',
    'username'       => '用户名',
    'password'       => '密码',
    'hostport'       => '数据库端口',

    二、在config.php配置第二个数据库连接



    'DB_Config_1'=>[
    'type'           => 'mysql',
    'hostname'       => '服务器IP地址',
    'database'       => '数据库名',
    'username'       => '用户名',
    'password'       => '密码',
    'hostport'       => '数据库端口'
    ],

    三、多数据库使用

    //默认数据库读取数据
    $test = Db::name("test")->select();
    //第二个数据库读取数据
    $test1=Db::connect("DB_Config_1")->name("test")->select();

     

    在项目开发中需要Thinkphp5读取多个数据库的数据,本文详细介绍Thinkphp5多数据库切换

    一、在database.php配置默认数据库连接




    'type'           => 'mysql',
    'hostname'       => '服务器IP地址',
    'database'       => '数据库名',
    'username'       => '用户名',
    'password'       => '密码',
    'hostport'       => '数据库端口',

    二、在config.php配置第二个数据库连接



    'DB_Config_1'=>[
    'type'           => 'mysql',
    'hostname'       => '服务器IP地址',
    'database'       => '数据库名',
    'username'       => '用户名',
    'password'       => '密码',
    'hostport'       => '数据库端口'
    ],

    三、多数据库使用

    //默认数据库读取数据
    $test = Db::name("test")->select();
    //第二个数据库读取数据
    $test1=Db::connect("DB_Config_1")->name("test")->select();

  • 相关阅读:
    快速开发框架:进销存业务注意事项
    延时执行函数:前浪死在沙滩上
    新增筛选方案
    进销存数据库设计:采购订单
    SasS 设计原则十二因素
    四种线程池的解析
    高并发下的流量控制
    Mybatis 缓存机制
    谈谈JVM垃圾回收
    如何使错误日志更加方便地排查问题
  • 原文地址:https://www.cnblogs.com/flzs/p/12190901.html
Copyright © 2011-2022 走看看