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
- Augmented Reality
- AWS
- Bioinformatics
- Biometrics
- Blockchain
- Bootstrap
- C
- C#
- C++
- Cloud Computing
- Competitions
- Courses
- CSS
- Cyber Security
- Data Science
- Data Structures and Algorithms
- Data Visualization
- Datafication
- Deep Learning
- DevOps
- Digital Forensic
- Digital Trust
- Digital Twins
- Django
- Docker
- Dot Net Framework
- Drones
- Elasticsearch
- ES6
- Extended Reality
- Flutter and Dart
- Full Stack Development
- Git
- Go
- HTML
- Image Processing
- IoT
- IT
- Java
- JavaScript
- Kotlin
- Latex
- Machine Learning
- MEAN Stack
- MERN Stack
- Microservices
- MongoDB
- NodeJS
- PHP
- Power Bi
- Projects
- Python
- Quantum Computing
- React
- Robotics
- Rust
- Scratch 3.0
- Shell Script
- Smart City
- Software
- Solidity
- SQL
- SQLite
- Tecgnology
- Tkinter
- TypeScript
- VB.NET
- Virtual Reality
- Web Designing
- WebAssembly
- XML