MongoDB - SPLessons
SPLessons 5 Steps, 3 Clicks
5 Steps - 3 Clicks

MongoDB PHP Driver

MongoDB PHP Driver

shape Description

By using mongodb in term of php then utilize the mongodb php driver.The demand for fast application development has brought some extra technical features to the database, broadly termed as NoSQL Database. And many of the develop application uses object oriented language. And to perform these objects we use polymorphism, if the objects are not in uniform then use inheritance. But mapping those tables and rows can be quite a bit problem. MongoDB PHP Driver contains no schema that can be defined, and there is no tables and relationship exits between collections and objects.

Connecting to the database

shape Description

To associate with MongoDB PHP Driver database, determine the database name into the classpath, if database is not determine then mongodb makes it consequently.

shape Examples

By viewing the below  example, one can easily understand how to connect to a database. [c] MongoDB shell version: 3.2.7 connecting to: test >show dbs admin 0.000GB demo 0.000GB local 0.000GB mydb 0.000GB testdb 0.000GB > use admin switched to db admin <?php // connect to mongodb $m = new MongoClient(); echo "Connection to database successfully"; // select a database $db = $m->mydb; echo "Database mydb selected"; ?> Connection to database successfully Database mydb selected[/c]

Creating a collections

shape Description

To associate with the database, determine the database name into the classpath, if database is not determine then mongodb makes it consequently.

shape Examples

By viewing the below  example, one can easily understand how to connect to a database. [c] MongoDB shell version: 3.2.7 connecting to: test > show dbs admin 0.000GB demo 0.000GB local 0.000GB mydb 0.000GB testdb 0.000GB > use admin switched to db admin <?php // connect to mongodb $m = new MongoClient(); echo "Connection to database successfully"; // select a database $db = $m->mydb; echo "Database mydb selected"; $collection = $db->createCollection("mycol"); echo "Collection created successfully"; ?> Connection to database successfully Database mydb selected Collection created successfully [/c]

Summary

shape Key Points

  • MongoDB PHP Driver - Install the PHP drivers on MongoDB database.