- php7
- php7-mongodb扩展
- composer 安装
composer require ninvfeng/mongodb
- 引入/vendor目录下的autoload.php
require 'vendor/autoload.php';
//推荐使用函数进行实例化,后续操作更加方便
function mongodb($table='null'){
static $_mongodb;
//配置
$config=[
'host'=>'127.0.0.1',
'port'=>27017,
'name'=>'test'
]
if(!$_mongodb){
$_mongodb=new \ninvfeng\mysql($config);
}
return $_mongodb->table($table);
}
mongodb('user')->insert(['user'=>'ninvfeng','pass'=>'password']);
mongodb('user')->insert(['user'=>'lvlv','pass'=>'password']);
mongodb('user')->where(['user'=>'ninvfeng'])->delete();
mongodb('user')->where(['user'=>'lvlv'])->update(['pass'=>'password2']);
mongodb('user')->where(['user'=>'lvlv'])->find();
mongodb('user')->page(1)->select();
mongodb('user')->where(['user'=>'lvlv'])->findAndRemove();
mongodb('user')->count();
mongodb('user')->func();
mongodb('user')->mongodb();