Vishal A
Vishal A

Reputation: 43

PHP with MongoDB

I'm trying to create a website using MongoDB to store user credentials (usernames and passwords). I would like to use PHP since I'm familiar with it but am having trouble with the syntax behind nearly everything in this regard (due to the updated php-mongodb driver). Are there any online resources to help, specifically, with adding and deleting information from a database? Any information is greatly appreciated.

Upvotes: 0

Views: 153

Answers (2)

helpdoc
helpdoc

Reputation: 1990

For Driver Connection issue you can check this link : PHP mongodb driver check connection


To use MongoDB with PHP, you need to use MongoDB PHP driver. Download the driver from the url Download PHP Driver. Make sure to download the latest release of it. Now unzip the archive and put php_mongo.dll in your PHP extension directory ("ext" by default) and add the following line to your php.ini file −

extension = php_mongo.dll

Make a Connection and Select a Database

To make a connection, you need to specify the database name, if the database doesn't exist then MongoDB creates it automatically.

Following is the code snippet to connect to the database −

<?php


// connect to mongodb
   $m = new MongoClient();

   echo "Connection to database successfully";
   // select a database
   $db = $m->mydb;

   echo "Database mydb selected";
?>

When the program is executed, it will produce the following result −

Connection to database successfully
Database mydb selected

Upvotes: 2

Nishant Nair
Nishant Nair

Reputation: 2007

You can have a look at below link which explains all about mongodb and php from scratch

https://www.sitepoint.com/building-simple-blog-app-mongodb-php/

Upvotes: 0

Related Questions