php - How to connect php7 with mongoDB -
i'm trying connect php 7 mongodb, installed "new" mongodb driver using pecl following page instructions. can see mongodb version 1.1.8 phpinfo()
output, can't figure out how initiate connection php code :p . following code includes attempts connect (tried connect using old fashion way)
// new fashion way $connection = new mongodb\driver\client(); // or using old fashion way $conn = new mongoclient(); // random try :p $randconn = new mongodb\client();
and in both cases, i'm getting not defined class exception. please let me know i'm missing , mistake, please provide , example easier follow if possible ;) .
ps: used operating system ubuntu 14.04 lts.
thanks in advance.
the page referring low-level php driver mongodb. api same hhvm driver mongodb. documentation both of them same, , can found @ http://docs.php.net/manual/en/set.mongodb.php
the driver written bare bone layer talk mongodb, , therefore misses many convenience features. instead, these convenience methods have been split out layer written in php, mongodb library. using library should preferred way of interacting mongodb.
the library needs installed composer, package manager php. see get composer: installation on linux/osx
for example:
composer require "mongodb/mongodb=^1.0.0"
once have installed, can try connecting using:
<?php require 'vendor/autoload.php'; $collection = (new mongodb\client("mongodb://127.0.0.1:27017"))->dbname->coll; ?>
see also:
Comments
Post a Comment