2017 © Pedro Peláez
 

library php7-mongo-driver

PHP7 Driver for MongoDb

image

thomas-squall/php7-mongo-driver

PHP7 Driver for MongoDb

  • Sunday, May 27, 2018
  • by ThomasSquall
  • Repository
  • 6 Watchers
  • 9 Stars
  • 71 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 5 Versions
  • 16 % Grown

The README.md

MongoDriver for PHP7

Latest Stable Version Build Status Coverage Status codecov Total Downloads License, (*1)

With the advent of PHP7 the old mongodb driver is no more supported., (*2)

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., (*3)

This is what this library was conceived for., (*4)

!!! FOR DETAILED GUIDELINES CONSULT THE WIKI AT: https://github.com/ThomasSquall/PHP7MongoDriver/wiki, (*5)

Installation

Using composer is quite simple, just run the following command: ``` sh $ composer require thomas-squall/php7-mongo-driver, (*6)


## 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: ``` sh $ sudo pecl install mongodb

After that you should put the following string ``` sh extension=mongodb.so, (*7)

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]], (*8)


For more information see the link: https://docs.mongodb.com/manual/reference/connection-string/ Once defined you need to instantiate a new Adapter: ``` php 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:, (*9)

``` php $adapter->selectDB('myDatabase');, (*10)

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:

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

You can also filter your query: ``` php use MongDriver\Filter;, (*11)

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

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


### 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: ``` php $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., (*14)

Please share it and give me a feedback :), (*15)

Thomas, (*16)

The Versions

27/05 2018

dev-master

9999999-dev

PHP7 Driver for MongoDb

  Sources   Download

MIT

The Requires

 

The Development Requires

by Thomas Cocchiara

16/01 2018

0.5.0

0.5.0.0

PHP7 Driver for MongoDb

  Sources   Download

MIT

The Requires

 

The Development Requires

by Thomas Cocchiara

14/01 2018

0.4.5

0.4.5.0

PHP7 Driver for MongoDb

  Sources   Download

MIT

The Requires

 

The Development Requires

by Thomas Cocchiara

10/01 2018

0.4.3

0.4.3.0

PHP7 Driver for MongoDb

  Sources   Download

MIT

The Requires

 

The Development Requires

by Thomas Cocchiara

05/01 2018

dev-models

dev-models

PHP7 Driver for MongoDb

  Sources   Download

MIT

The Requires

 

The Development Requires

by Thomas Cocchiara