• 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();

  • 相关阅读:
    学习java的第二天
    第一天学习JAVA
    java小知识字符串,比较object,equalsIgnoreCase()拼接concat /截取substring
    java小知识api Scanner Random ArrayList
    java小知识对象
    java小知识数组
    java小知识方法
    java基础知识循环语句
    java小知识语句
    java基础小知识
  • 原文地址:https://www.cnblogs.com/flzs/p/12190901.html
Copyright © 2020-2023  润新知