Skip to content

一个简单的php7 mongodb数据库操作类

Notifications You must be signed in to change notification settings

ninvfeng/mongodb

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 

Repository files navigation

一个简单的PHP Mongodb单文件操作类

依赖

  • php7
  • php7-mongodb扩展

安装

  1. composer 安装 composer require ninvfeng/mongodb
  2. 引入/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();

About

一个简单的php7 mongodb数据库操作类

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages