本文实例讲述了tp5(thinkphp5)操作mongodb数据库的方法。分享给大家供大家参考,具体如下:
1.通过composer安装
composer require mongodb/mongodb
2.使用
<?php
/**
* @author: jim
* @date: 2017/11/17
*/
namespace appindexcontroller;
use thinkcontroller;
use mongodbdrivermanager;
use mongodbcollection;
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相关内容感兴趣的读者可查看本站专题:《thinkphp入门教程》、《thinkphp模板操作技巧总结》、《thinkphp常用方法总结》、《codeigniter入门教程》、《ci(codeigniter)框架进阶教程》、《zend framework框架入门教程》及《php模板技术总结》。
希望本文所述对大家基于thinkphp框架的php程序设计有所帮助。
【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:)!