MongoDB Driver for PHP – Install and Connect

MongoDB is an open-source leading NoSql database. In my previous posts , I explain the MongoDB terminology, installation process,creating and quering DB. In this article i will explain how to install and connect MongoDB with PHP.

Let’s quickly go through the popular terminology used in MongoDB

Database – In RDBMS database is a collection of tables. In Mongo Database is a set of collections.

Collections – Collection in mongodb is like a table in mysql. But it does not have schema. It is a schema-less.

Document – It is like a record or row in relational databases (like mysql). It is stored in BSON (Binary Json) format.

How to Install and Create Database with MongoDB

Quering document in MongoDB

Installing MongoDB Driver for PHP

I assume you have already installed LAMP (for linux users) on your system.

Installed some dependency

To install Mongodriver for PHP

After installing mongodriver, you need to add extension = mongo.so in your php.ini file.

After adding extension in php.ini file. Restart the Apache server.

Subscribe Our Tutorials

Get Latest Updates on Facebook

To restart, type

To check MongoDB driver installation, use

MongoDB driver

Now we have installed MongoDB driver for PHP. Let’s write some PHP code for connecting to MongoDB.

MongoDB Installation Guide for Windows User

Connect with PHP

I am using bookmarks DB which i already created. Now i am accessing the records of emp collection.

Add Collection

Creating connection object.

Use bookmarks database.

creating new collection product under bookmarks database.

Make product array for insertion.

Insert the Value

To check the inserted record open terminal

Conclusion

Hope this article is helpful, for installation and creating MongoDB connection to PHP.

WebRewrite

About WebRewrite

I am technology lover who loves to keep updated with latest technology. My interest field is Web Development.
Tagged , , , . Bookmark the permalink.