一起源码网

标题: tp5操作mongoDB数据库实例 [打印本页]

作者: 云文章    时间: 2020-6-7 14:30
标题: tp5操作mongoDB数据库实例
本文主要介绍了tp5(thinkPHP5)操作mongoDB数据库的方法,结合实例形式简单分析了mongoDB数据库及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';
  }
}


作者: 阿一    时间: 2022-10-18 10:30
用python实现办公自动化pdf




欢迎光临 一起源码网 (https://www.171739.xyz/) Powered by Discuz! X3.3