前提先装好对应PHP驱动和tp的mongodb驱动
以tp5为例,假设mongodb集群配置:
那么数据库配置应该:
// 数据库类型
'type' => '\think\mongo\Connection',
// 服务器地址
'hostname' => '192.168.1.101,192.168.1.102,192.168.1.103',
// 数据库名
'database' => 'test',
// 数据库用户名
'username' => 'xxxx',
// 数据库密码
'password' => 'xxxxxx',
// 数据库编码默认采用utf8
'charset' => 'utf8',
// 数据库表前缀
'prefix' => '',
// 数据库调试模式
'debug' => false,
// 端口
'hostport' => '37011,37012,37012',
// 数据库连接参数
'params' => ['replicaSet'=>'mongodbs'],
注意,一定要把参数带上