The following code example shows how to create a MongoDB database using PHP Script.
Using the given server address and other default options, the MongoClient class creates an instance of Mongo. The next statement creates a database with the name ‘Blog’ if it doesn’t exist already. However, if the database is already there, it is selected.
<?php
// connect to mongodb
$db_manager = new MongoClient();
echo "Connected!";
// select a database
$database = $db_manager->Blog;
echo "<br>Selecting the Blog Database....";
?>
Output

As can be seen in the following figure, the GUI client of Mongo, the MongoDB Compass shows the newly created database ‘Blog‘.

Further Reading
Working with MongoDB Compass
Create a collection in a MongoDB database in PHP
Insert Documents in a Collection
Show All Documents in a Collection
- AI
- Android
- Angular
- ASP.NET
- AWS
- Bootstrap
- C
- C#
- C++
- Cloud Computing
- Competitions
- Courses
- CSS
- Data Science
- Data Structures and Algorithms
- Deep Learning
- DevOps
- Django
- Docker
- Dot Net Framework
- Drones
- Go
- HTML
- IoT
- Java
- JavaScript
- Kotlin
- Latex
- Machine Learning
- MEAN Stack
- MERN Stack
- MongoDB
- NodeJS
- PHP
- Power Bi
- Projects
- Python
- React
- Scratch 3.0
- Smart City
- Software
- Solidity
- SQL
- TypeScript
- VB.NET
- Web Designing
- XML