定制 alex-qiu/php7-mongo-adapter 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

alex-qiu/php7-mongo-adapter

Composer 安装命令:

composer require alex-qiu/php7-mongo-adapter

包简介

php7 mongodb adapter

README 文档

README

Latest Stable Version Build Status Coverage Status codecov Total Downloads License

With the advent of PHP7 the old mongodb driver is no more supported.

The new driver available is a little bit low-level compared to the previous one so it can be a bit complicated to work with.

This is what this library was conceived for.

Installation

Using composer is quite simple, just run the following command:

$ composer require alex-qiu/php7-mongo-adapter

Prerequisites

Before using this library you should make sure to have installed PHP7.0 or major and MongoDb driver from pecl.

For those using a Linux distribution (make sure to have pecl installed) just run:

$ sudo pecl install mongodb

After that you should put the following string

extension=mongodb.so

Inside your php.ini

Usage

At first you need to define a connection string.

The format for connection strings is:

mongodb://[username:password@]host1[:port1][,host2[:port2],...[,hostN[:portN]]][/[database][?options]]

For more information see the link: https://docs.mongodb.com/manual/reference/connection-string/

Once defined you need to instantiate a new Adapter:

use MongoDriver\Adapter;

// Enstablish a connection.
$adapter = new Adapter();
$adapter->connect(CONNECTION_STRING);

At this point you want to select a Database where do your query:

$adapter->selectDB('myDatabase');

NOTE: you could select a database directly on the constructor passing the database name as the 2nd parameter.

Find

Once selected the database we can simply query for the collection we want:

$items = $adapter->find('myCollection');

You can also filter your query:

use MongDriver\Filter;

$filters =
[
    new Filter('myField1', 'myValue1', Filter::IS_EQUALS),
    new Filter('myField2', ['myValue2', 'myValue3'], Filters::IS_IN_ARRAY)
];

$items = $adapter->find('myCollection', $filters);

Insert

If you want to insert an item you have simply to pass an array or an object to the insert function specifying the collection:

$item = new Person();
$item->name = 'Thomas';
$item->surname = 'Cocchiara');

// or: $item = ['name' => 'Thomas', 'surname' => 'Cocchiara'];

$adapter->insert('people', $item);

Hope you guys find this library useful.

Please share it and give me a feedback :)

Alex

统计信息

  • 总下载量: 22
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2018-11-06

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固