MongoDb With Php Dll Not Working - php

I'm having wamp on my windows machine with php 5.5.12 and I have installed mongodb 3.2.0 (64 bit) and added php 1.5.7 dll in wampp extension and completed all the necessary things which required to connect with the mongodb.
Here is my code for connecting the mongoDb.
<?php
// connect to mongodb
$m = new MongoClient();
echo "Connection to database successfully";
// select a database
$db = $m->portal;
echo "Database mydb selected";
?>
error message while connecting to db

6.8 Mongo and instantiating the class as follows
php info mongo db
/*Hello I'm Using 1.6.8 Mongo and instantiating the class as follows*/
$mongo = new MongoClient();
$db = $mongo->gwb;
$collection = $db->users;

Related

How to setup MongoDB with wamp server

I want to use MONGO db with my wampserver3.0.6_x64_apache2.4.23_mysql5.7.14_php5.6.25-7.0.10. I have successfully installed MSI(mongodb-win32-x86_64-2008plus-ssl-3.4.3-signed) and also DLL file for the PHP setup on my Windows 10 Pro, 64-bit Operating System, x64-based processer. But when i go through the below code
echo extension_loaded("mongodb") ? "loaded\n" : "not loaded\n";
echo extension_loaded("mysql") ? " mysql loaded\n" : " mysql not loaded\n";
// connect to mongodb
$m = new MongoClient();
echo "Connection to database successfully";
// select a database
$db = $m->mydb;
echo "Database mydb selected";
its says ---not loaded and -- mysql loaded and Fatal error: Class 'MongoClient' not found in C:\wamp64\www\mongotest\conn.php on line 5.
I appreciate any help on this.

Cannot connect mongoDB and PHP

I am successfully running mongoDB v3.2.10 in terminal on macOS 10.11.6 and MAMP server running php 7.0.8.
When I try to reach mongo via php code like:
<?php
// connect to mongodb
$m = new MongoClient();
?>
at url: http://localhost:8888/Mongo/login.php
I get:
This site can’t be reached
localhost refused to connect.
When I reach mongo on the native port
at url: http://localhost:27017/Mongo/login.php
I get:
It looks like you are trying to access MongoDB over HTTP on the native
driver port.
Any idea what am I missing here?
Looks like you are using the built-in PHP Mongo DB clients. There is a new MongoDB driver that replace that. You will have to install it.
http://php.net/manual/en/set.mongodb.php
The newer MongoDB extension replaces the built-in PHP Mongo DB client. You'll also want to use the composer PHPLIB MongoDB client from here: http://php.net/manual/en/mongodb.tutorial.library.php
use MongoDB\Client;
try {
$mongoDbClient = new Client('mongodb://localhost:27017');
} catch (Exception $error) {
echo $error->getMessage(); die(1);
}

Class 'MongoClient' not found in xampp

I want to connect mongodb with php.
PHP version : 5.6
Mongodb:
System : 64 bit
Xampp : v3.2.1
Window : 7
I have added php_mongo.dll (as per system 64 bit) into php.ini file and copied that dll into php/ext folder.when i am trying to connect, i am getting following message.
Fatal error: Class 'MongoClient' not found in D:\xampp\htdocs\
connection file
<?php
$MongoDBConnection = new MongoClient();
$DB = $MongoDBConnection->selectDB('SimpleCrud');
$pessoas = $DB->pessoas;
?>
To use MongoDB with PHP, you need to use MongoDB PHP driver. CLICKHERE to download the driver. Make sure to download the latest release of it. Now unzip the archive and put php_mongo.dll in your PHP extension directory ("C:\xampp\php\ext" by default) and add the following line to your php.ini file.
extension = php_mongo.dll
Following is the code snippet to connect to the database :
<?php
// connect to mongodb
$m = new MongoClient();
echo "Connection to database successfully";
// select a database
$db = $m->myTestdb; // myTestdb-> Your Database Name
echo "Database myTestdbselected";
?>
When the program is executed, it will produce the following result −
Connection to database successfully
Database myTestdb selected

Class 'MongoClient' not found, while php connecting to mongodb in ubuntu

I installed mongodb version 3.0.7 in xampp, and installed php driver also. below is the php code to connect mongodb.
<?php
// connect
$m = new MongoClient();
// select a database
$db = $m->test;
?>
While I run this code in my localhost I am getting this error
Fatal error: Class 'MongoClient' not found in /opt/lampp/htdocs/mongo.php on line 3
<?php
// connect
$m = new MongoClient();
// select a database
$db = $m->test;
?>
This above code working fine, In xampp server you must include "extension=mongo.so" in php.ini file at usr/lib/php5/20121212/php.ini with same extension. After all setting restart your server.

Mongodb installation

Mongodb installed in linux CentOS server (ssh) with steps mentioned in this url
http://docs.mongodb.org/manual/tutorial/install-mongodb-on-red-hat/
Started MongoDB server using the command and the status is ok.
sudo service mongod start
When connecting mongodb with PHP (Yii app), it shows error like this.
include(MongoClient.php) [<a href='function.include'>function.include</a>]: failed to open stream: No such file or directory
PHP code
<?php
// connect to mongodb
$m = new MongoClient();
echo "Connection to database successfully";
// select a database
$db = $m->health;
echo "Database mydb selected";
$collection = $db->medical;
echo "Collection selected succsessfully";
?>
Yii2 provide class yii\mongodb\Connection for mongodb connection.
Check below link.
http://www.yiiframework.com/doc-2.0/yii-mongodb-connection.html
MongoDb Extension for Yii 2
http://www.yiiframework.com/doc-2.0/ext-mongodb-index.html
It will resolve your issue.

Categories