lumen使用mongodb
1.安装mongodb扩展
执行sudo pecl install mongodb
如果是windows,到https://windows.php.net/downloads/pecl/releases/mongodb/选择对应的版本下载,并把php_mongodb.dll复制到php的ext目录
2.配置扩展
在php.ini中增加以下语句
extension=mongodb.so
3.在lumen中引入mongodb驱动
在composer文件添加"jenssegers/mongodb":"3.4.5",然后执行
composer update
4.在lumen的bootstrap/app.php中注册驱动,并且必须开通withEloquent。MongodbServiceProvider的注册应该在其它服务之前,否则可能导致Unsupportdriver错误
$app->register(Jenssegers\Mongodb\MongodbServiceProvider::class); .... .... $app->withEloquent();
5.在config/database.php配置mongodb连接参数
'mongodb' => [ 'host' => '127.0.0.1', 'port' => 27017, 'username' => '', 'password' => '', 'database' => 'test', ],
参考:
https://www.jianshu.com/p/41865e061648
http://www.runoob.com/mongodb/php7-mongdb-tutorial.html
相关推荐
lbyd0 2020-11-17
BigYellow 2020-11-16
sushuanglei 2020-11-12
我心似明月 2020-11-09
zhushenghan 2020-11-09
sunnnyduan 2020-10-16
不要皱眉 2020-10-14
xiaohai 2020-09-29
songxiugongwang 2020-09-22
萌亖 2020-09-17
LuckyLXG 2020-09-08
sdmzhu 2020-09-01
mkhhxxttxs 2020-09-16
xiaohai 2020-09-16
newcome 2020-09-09
jaylong 2020-08-19
大秦铁骑 2020-08-19
thatway 2020-08-19