I want to use mongodb
with php
. I have installed Binami Wamp Stack 5.6
. phpinfo()
is working fine but on running the code below, I found this error
The localhost page isn't working localhost is currently unable to handle this request.
<?php
// connect to mongodb
$m = new MongoClient();
echo "Connection to database successfully";
// select a database
$db = $m->mydb;
echo "Database mydb selected";
?>
I also tried with $m = new MongoDB\\Driver\\Manager("mongodb://localhost:27017");
but same error.
There are two .dll
of mongo
named php_mongo.dll
and php_mongodb.dll
are already in php
folder inside ext
folder. Can some one help me?
You need to edit the configuration file php.ini and uncomment the line below:
;extension=php_mongodb.dll
Removing the ;
at the beggining.
After that, you have to restart Apache. You can use the Bitnami Manager to do that.
Finally, you can check that it is working with this small example:
<?php
// connect to mongodb
$manager = new MongoDB\Driver\Manager("mongodb://localhost:27017");
var_dump($manager);
?>
I hope this information is useful for you. If you have any other question, please do not hesitate to let us know.
Best Regards,
Juan Ariza
My db connection as follow
function get_db_con() {
$mongo = new MongoClient();
$db = $mongo->my_db_name;
return $db;
}
And i called above function like this:
function my_function() {
$db = get_db_con(); // I call function for db connection
}
and its working for me!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.