本文實(shí)例講述了tp5(thinkPHP5)操作mongoDB數(shù)據(jù)庫(kù)的方法。分享給大家供大家參考,具體如下:
1.通過(guò)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() {
// 讀取一條數(shù)據(jù)
$data = $this->mongoCollection->findOne();
print_r($data);
}
protected function getUri()
{
return getenv('MONGODB_URI') ?: 'mongodb://127.0.0.1:27017';
}
}

更多關(guān)于thinkPHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《ThinkPHP入門教程》、《thinkPHP模板操作技巧總結(jié)》、《ThinkPHP常用方法總結(jié)》、《codeigniter入門教程》、《CI(CodeIgniter)框架進(jìn)階教程》、《Zend FrameWork框架入門教程》及《PHP模板技術(shù)總結(jié)》。
希望本文所述對(duì)大家基于ThinkPHP框架的PHP程序設(shè)計(jì)有所幫助。
您可能感興趣的文章:- tp5.1框架數(shù)據(jù)庫(kù)子查詢操作實(shí)例分析
- tp5.1 框架數(shù)據(jù)庫(kù)常見(jiàn)操作詳解【添加、刪除、更新、查詢】
- tp5.1 框架數(shù)據(jù)庫(kù)高級(jí)查詢技巧實(shí)例總結(jié)
- ThinkPHP5.1框架數(shù)據(jù)庫(kù)鏈接和增刪改查操作示例
- PHP利用pdo_odbc實(shí)現(xiàn)連接數(shù)據(jù)庫(kù)示例【基于ThinkPHP5.1搭建的項(xiàng)目】
- PHP7使用ODBC連接SQL Server2008 R2數(shù)據(jù)庫(kù)示例【基于thinkPHP5.1框架】
- ThinkPHP實(shí)現(xiàn)多數(shù)據(jù)庫(kù)連接的解決方法
- thinkPHP5實(shí)現(xiàn)的查詢數(shù)據(jù)庫(kù)并返回json數(shù)據(jù)實(shí)例
- tp5(thinkPHP5)框架數(shù)據(jù)庫(kù)Db增刪改查常見(jiàn)操作總結(jié)
- tp5(thinkPHP5)框架實(shí)現(xiàn)多數(shù)據(jù)庫(kù)查詢的方法
- thinkPHP5實(shí)現(xiàn)數(shù)據(jù)庫(kù)添加內(nèi)容的方法
- tp5.1 框架數(shù)據(jù)庫(kù)-數(shù)據(jù)集操作實(shí)例分析