0

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.

1
  • Its a bit late but you can refer to this basic tutorial on php mongodb. programmerblog.net/php-mongodb-tutorial hope this helps any body in future also Commented Jun 9, 2017 at 6:43

2 Answers 2

2

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
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks! This really helped!
Welcome @VishalA, Accept answer if you satisfied
0

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/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.