配置文件中,mongo配置下,db_name不生效
配置:<?php <br />
return [<br>
//默认数据库配置<br>
'DB_TYPE' => 'mysql',<br>
'DB_HOST' => '127.0.0.1', // 服务器地址<br>
'DB_NAME' => 'test', // 数据库名<br>
'DB_USER' => 'root', // 用户名<br>
'DB_PWD' => 'wh111111', // 密码<br>
'DB_PORT' => '3306', // 端口<br>
'DB_PREFIX' => '', // 数据库表前缀<br>
'DB_DEBUG' => TRUE, // 数据库调试模式 开启后可以记录SQL日志 3.2.3新增\<br>
//mongodb<br>
'DB_MONGO' => [<br>
'DB_TYPE' => 'mongo',<br>
'DB_HOST' => '127.0.0.1', // 服务器地址<br>
'DB_PORT' => '27018', // 端口<br>
'DB_NAME' => 'myMongo', // 数据库名<br>
'DB_USER' => '', // 用户名<br>
'DB_PWD' => '', // 密码<br>
'DB_PREFIX' => '', // 数据库表前缀<br>
]<br>
];
model模型:use Think\Model\MongoModel as baseModel;<br>
<br>
class RequestLogModel extends baseModel {<br>
<br>
/**<br>
* 指定model链接的数据库,值为db config的 key<br>
* <br>
* @var string<br>
*/<br>
protected $connection = 'DB_MONGO';<br>
<br>
}
controller中使用:$model = D('RequestLog');<br>
$model->create();<br>
$model->module = "platform";<br>
$model->controller = "RequestLog";<br>
$model->action = "index";<br>
$model->time = strval(time());<br>
$model->add();
配置文件中DB_MONGO下的DB_NAME不起作用, 用的是系统默认的数据库配置下的DB_NAME, 但是DB_MONGO配置下的其它参数都有效,操作完之后,用终端show databases; 只有test数据库,数据也存到了test下requestlog集合中,没有myMongo数据库,请知道的兄弟给个解决办法,先谢谢啦
AD:真正免费,域名+虚机+企业邮箱=0元

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver Mac version
Visual web development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 Chinese version
Chinese version, very easy to use