thinkphp5本地数据库表和外接数据库表一对多问题,求大神来解决
为什么我做的本地表和其他服务器数据库表关联,如果把数据库配置项写在配置文件里怎么查他都是查其他服务器数据库表中的一张,但是把配置项写在模型里又是正常可以使用.
这是本地表模型,一对多关联外接表
<?php
namespace app\admin\model;
use think\Model;
class Wxuser extends Model{
protected $table = 'qgs_admin';
protected $hidden = ['pwd','name','email','headimg','createtime'];
protected $pk = 'id';
public function wxshop_panel(){
return $this->hasOne('WxshopPanel','qgs_admin_id')->field(['url','id','title','img']);
}
public function shopuser_behaviors(){
return $this->hasMany('ShopuserBehavior','qgs_admin_id');
}
public function product_carts(){
return $this->hasMany('ProductCart','token','token');
}
public function product_cart(){
return $this->hasOne('ProductCart','token','token');
}
public function product_shop_parcel(){
return $this->hasOne('ProductShopParcel','rid','id');
}
}
这事其中外接表的模型,然后其他外接表一样这样写法
<?php
namespace app\admin\model;
use think\Model;
use SoftDelete;
class ProductShopParcel extends Model{
protected $autoWriteTimestamp = 'datetime';
protected $deleteTime = 'delete_time';
protected $table = 'wy_product_shop_parcel';
protected $connection = [
// 数据库类型
'type' => 'mysql',
// 服务器地址
'hostname' => '',
// 数据库名
'database' => 'wxtest',
// 数据库用户名
'username' => 'wxtest',
// 数据库密码
'password' => '',
// 数据库编码默认采用utf8
'charset' => 'utf8',
// 数据库表前缀
'prefix' => 'wy_',
// 数据库调试模式
'debug' => false,
];
// function __construct(){
// $this->connection = Config('olddb');
// }
}
这样是可以正常使用的,但如果我把这配置项写到配置文件后,用Config(‘配置项名’)在方法里写,调用模型类,他只会随意读回第一张外接表,很奇怪,求指导
- ghost和wordpress,哪种选择更好?
- js跨域请求问题
- 想要去除iframe广告,可他的ID值每刷新一次,后面的5个英文都在变?
- contenteditable="true"无法提交到php,该怎么办?
- 用PHP做ios推送在linux环境下使用stream_socket_client报错
- php中的Model到底扮演什么角色
- 全局包含一个config.php是不是会增加内存消耗?
- 搭建smarty模板引擎环境,但是没有后端,没有php环境,大牛给点资源帮忙搭建起来
但如果我把这配置项写到配置文件后,用Config(‘配置项名’)在方法里写
你是怎么写的啊?
如果你不把配置写在model里面,还可以
Db::connect('db_config')