MongoDB and Php Beginner Tutorials
- Last Updated on: April 24, 2013
- By: scriptcrunch
Database connection:
Connecting mongoDB with php is really simple if your configured php with mongoDB using php driver. Assuming that you have already configured php with mongoDB am going to explain the php script to connect mongoDB. For configuring mongoDb with php inlinux , you can follow this link. How to Configure Php with mongoDb on Ubuntu
Sample Php web app using mongoDB:
Connecting mongoDB with php is really simple if your configured php with mongoDB using php driver. Assuming that you have already configured php with mongoDB am going to explain the php script to connect mongoDB. For configuring mongoDb with php inlinux , you can follow this link. How to Configure Php with mongoDb on Ubuntu
Sample Php web app using mongoDB:
<?php
//connect to mongoDB using mongo class
$m = new Mongo();
//selecting the database, which will be created on the fly
$db = $m->selectDB("comtechies");
//creating or selecting a collection. If the collection is already there it will be selected or it will be created on the fly.
$collection = $db->comtechies->demo;
//creating a document with array
$doc = array(
"name" => "bibin",
"place" => "kollemcode",
"position" => "admin"
);
//inserting the document in to collection
$collection->insert($doc);
//store the first row in the collection to the variable result
$result = $collection->findone();
//shows the result
var_dump($result);
?>
Other Interesting Blogs

CKA Exam Study Guide: Certified Kubernetes Administrator
Passing the cloud-native Certified Kubernetes Administrator (CKA) exam is not a cakewalk. To pass the CKA exam, you should have enough hands-on

Linux Foundation Coupon for 2023
Hi Techies, I wanted to let you know about a pretty sweet deal with the Linux Foundation Coupon that is running now.

[35% OFF] Linux Foundation LFCA, LFCS & LFCT Exam Voucher Codes
Linux Foundation has announced up to a $284 discount on its Linux certification programs Linux Foundation Certified IT Associate (LFCA) and Linux