The MongoDB is built to work with your current web server, but not PHP. To communicate PHP with MongoDB server you need to install PHP-MongoDB driver. The PHP-MongoDB driver is a PHP extension library. The presently maintained driver for the MongoDB PHP extension on the market from PECL.
To install driver library follow the below URL
http://docs.php.net/manual/en/mongodb.tutorial.install.php
If you use Linux install it easily via:
sudo pecl install mongo
After installing driver you need to update your php.ini file with below option.
extension = php_mongo.dll
Restart your web server and verify via command line:
php -i |grep "mongo"
php --re mongo
Making connection with MongoDB in PHP
To make connection with MongoDB using PHP you need to specify database name. If database is not exist then mongoDB will create anew database by itself.
<?php
// connect to mongodb
$mongo = new MongoClient();
// select a database
$db = $mongo->mydb;
echo "Database mydb selected";
?>
0 Comment(s)