Connecting to MongoDB in PHP
Learn about the PHP driver for MongoDB and how to use it to connect your PHP applications to your MongoDB database.
Connecting to MongoDB in PHP
Unit Overview
In this unit, you'll learn how to connect a PHP application to a MongoDB Atlas cluster by using the official MongoDB PHP driver. First, you'll learn what MongoDB drivers are and how they’re used to connect applications to MongoDB. Next, you'll install the MongoDB PHP driver extension and library and use your connection string to connect your application to the database. Finally, you'll learn how to troubleshoot some common connection and authentication issues.
Prerequisite
Lessons in This Unit
- Lesson 1: Using the MongoDB PHP Driver
- Lesson 2: Installing the MongoDB PHP Driver
- Lesson 3: Connecting to an Atlas Cluster in PHP Applications
- Lesson 4: Troubleshooting a MongoDB Connection in PHP Applications
-
01.
-
02.Lesson 2: Installing the MongoDB PHP Driver
- Learn
- Practice
-
03.Lesson 3: Connecting to an Atlas Cluster in PHP Applications
- Learn
- Practice
-
04.Lesson 4: Troubleshooting a MongoDB Connection in PHP Applications
- Learn
- Practice
-
05.Conclusion
- Learn
Julie Gauthier | Senior Curriculum Engineer
Julie is a Senior Curriculum Engineer on the University Team at MongoDB. She holds a BS and MS in Computer Science, and has a background as a software engineer. Julie has taught hundreds of people web development, with a goal of empowering everyone with technology!
Vick Mena | Director, Curriculum
My name is Vick and I've been in the wild for over 25 years. I grew up at IBM working on the BIOS for the IBM eServer line in Austin, TX before moving to Wall St. I've worked on all phases of software development from low-level to middleware to UI but feel most comfortable in the middle. I also drank the devops kool-aid having moved a product line to AWS while at Dow Jones & Co with the help of an amazing team. I then pivoted into the secure space and worked on software/hardware reverse engineering. I always thought I'd eventually teach and this role lets me leverage all of my experience to lead this motley crew of passionate educators.
Hi there! Welcome to this unit on working with the MongoDB PHP driver. In this unit, you’ll learn how to connect a PHP application to a MongoDB Atlas cluster by using the official PHP driver from MongoDB.
I’m Julie. I’m a Curriculum Engineer at MongoDB, and I’ll be working with you through this unit.
MongoDB provides a PHP extension and a library to make connecting to a MongoDB cluster straightforward. Configuring the extension and the library can be a little tricky, but we’ll show you how to do that in this unit.
MongoDB is powerful on its own. But, pairing it with a driver opens up even more possibilities. We’ll explore these possibilities throughout the unit.
By using the driver, you can take advantage of MongoDB Atlas clusters in PHP applications.
The lessons in this unit consist of videos followed by quiz questions and labs so that you can practice what you learned.
First, you will learn how MongoDB drivers are used to connect applications to MongoDB.
Then, we’ll show you how to install the MongoDB PHP driver by using PECL, a PHP extension manager, and how to install the MongoDB PHP library by using Composer, a PHP dependency manager. We’ll create a MongoDB client instance in our code and use it to connect to our Atlas cluster.
Finally, we’ll troubleshoot a few of the most common connection and authentication issues.
Before you begin this unit, you should have a basic understanding of: PHP, MongoDB databases and the document model, and Atlas, the MongoDB developer data platform.
You will also need to set up an Atlas account.
By the end of this unit, you will be able to install the MongoDB PHP driver extension and library, use your connection string to connect your application to the database, and troubleshoot common connection and authentication errors.
Let’s get started!
