Posted in PHP onJanuary 20, 2018
本文实例讲述了tp5(thinkPHP5)操作mongoDB数据库的方法。分享给大家供大家参考,具体如下:
1.通过composer安装
composer require mongodb/mongodb
2.使用
<?php /** * @author: jim * @date: 2017/11/17 */ namespace app\index\controller; use think\Controller; use MongoDB\Driver\Manager; use MongoDB\Collection; class MongoTest extends Controller { protected $mongoManager; protected $mongoCollection; public function __construct() { $this->mongoManager = new Manager($this->getUri()); $this->mongoCollection = new Collection($this->mongoManager, "mldn","dept"); } public function test() { // 读取一条数据 $data = $this->mongoCollection->findOne(); print_r($data); } protected function getUri() { return getenv('MONGODB_URI') ?: 'mongodb://127.0.0.1:27017'; } }
希望本文所述对大家基于ThinkPHP框架的PHP程序设计有所帮助。
tp5(thinkPHP5)操作mongoDB数据库的方法
- Author -
TBHacker声明:登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。
Reply on: @reply_date@
@reply_contents@