Getting Started with MongoDB and PHP

This tutorial provides an introduction to basic database operations using the mongo shell. MongoDB is a document database that provides high performance, high availability, and easy scalability.

MongoDB is a free and open-source cross-platform document-oriented database program with NoSQL database. It stores data in json format. MongoDb is developed by MongoDB Inc in 2007.


How Access MongoDB from PHP

To access MongoDB from PHP you need:

1) The MongoDB server running. The server is the “mongod” file,
not the “mongo” client (note the “d” at the end).
2) The MongoDB PHP driver installed.

Make a connection string & Select a database

To make connection string & select the database in php simply used the below snippets.
Create a config.php file.

Select all Data

Delete Data

In the part of useful CRUD there is ability to delete the data records. MonogoDB provides a method remove() for this which only takes an array of data attributes as the criteria to removing the data records.

Update the data

In the CRUD operations there is also ability to update the records. In MongoDB have a simple method save() for this which require an array of criteria to know which records would be updated. Bellow is the example fo updating the data records.

If you like FreeWebMentor and you would like to contribute, you can write an article and mail your article to [email protected] Your article will appear on the FreeWebMentor main page and help other developers.

Recommended Posts:

Article Tags: , , , , , , , ,