Javatpoint Logo
Javatpoint Logo

Php MongoDB Connectivity

Php provides mongodb driver to connect with mongoDB database. After installing it, we can perform database operations by using the php. Here, we are using Ubuntu 16.04 to create an example. This example includes the following steps.

1) Installing Driver

MongoDB Php mongodb connectivity 1

2) Edit php.ini File

It is store in the apache server directory /etc/php/7.0/apache2/php.ini

MongoDB Php mongodb connectivity 2

3) Install mongo-php library

Following is the preferred way of installing this library with Composer.

MongoDB Php mongodb connectivity 4

4) Create Php Script

// connect.php

5) Execute Php Script

Execute this script on the localhost server. It will create database and store data into the mongodb.

MongoDB Php mongodb connectivity 5

6) Enter into Mongo Shell

After executing php script, we can see the created database in mongodb.

MongoDB Php mongodb connectivity 6

6.1. Show Database

The following command is used to show databases.

MongoDB Php mongodb connectivity 7

6.2. Show Collection

The following command is used to show collections.

MongoDB Php mongodb connectivity 8

6.3. Access Records

MongoDB Php mongodb connectivity 9

Well all set, this is working fine. We can also perform other database operations as well.


Next TopicPython MongoDB




Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


B.Tech / MCA