Blogger Information
Blog 38
fans 0
comment 3
visits 43813
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
配置多个数据库
意外的博客
Original
1324 people have browsed it
<?php
//在页面app/config/database.php中配置的,这两个文件都是自己添加的;


//创建一个和默认database.php一样的文件在同一级别,里面的配置项仅仅将数据库名改动;
//引入创建的文件;
//在return最下面将$luxiansheng 赋值,一起返回到配置类里;
$luxiansheng = require_once('databasetwo.php');

return [
	'type'            => 'mysql',
    // 服务器地址
    'hostname'        => '127.0.0.1',
    // 数据库名
    'database'        => 'luheng',
    // 用户名
    'username'        => 'root',
    // 密码
    'password'        => 'root',
    // 端口
    'hostport'        => '',    //默认端口为3306;
    // 连接dsn
    'dsn'             => '',
    // 数据库连接参数
    'params'          => [],
    // 数据库编码默认采用utf8
    'charset'         => 'utf8',
    // 数据库表前缀
    'prefix'          => '',

    //配置第二个数据库;
    'luxiansheng' => $luxiansheng
];
<?php
//控制器同一级别的model层;

namespace app\admin\model;

use think\Model;

class TextModel extends Model
{
    //声明连接的数据库;
	protected $connection = 'luxiansheng';
	protected $table = 'admins';
	protected $pk = 'id';


}

最后在控制器操作即可;

Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post