1、config.php 添加:

'db_config1' => 'mysql://brand:123456@127.0.0.1:3306/brand#utf8',

字符串连接的定义格式为:

数据库类型://用户名:密码@数据库地址:数据库端口/数据库名#字符集

2、对应的模型里:

   protected $connection = 'db_config1';

    // 表名
    protected $name = '数据库对应的表名';

protected $connection ='mysql://brand:123456@127.0.0.1:3306/brand#utf8';

// 表名
protected $name = '数据库对应的表名';

 

use think\Model;
use traits\model\SoftDelete;

class Teshubranddo extends Model
{

    use SoftDelete;



    protected $connection = 'db_config1';

    // 表名
    protected $name = 'teshu_brands02';

    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'timestamp';

    // 定义时间戳字段名
    protected $createTime = 'created_at';
    protected $updateTime = 'updated_at';
    protected $deleteTime = 'deleted_at';

    // 追加属性
    protected $append = [
        'state_text',
        'untype_text',
        'is_get_text'
    ];

Logo

一站式 AI 云服务平台

更多推荐