Home > Backend Development > PHP Tutorial > How to operate MongoDB database in PHP (implementation of database connection and simple statistics)

How to operate MongoDB database in PHP (implementation of database connection and simple statistics)

不言
Release: 2023-04-03 21:48:01
Original
1965 people have browsed it

The content of this article is about how to operate MongoDB database in PHP (implementation of connecting database and simple statistics). It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

1. Connect to the MongoDB database (on the premise that the php-mongodb extension has been installed)

$config = "mongodb://{$user}:{$pass}@{$host}:{$port}";
$mongodb = new \MongoDB\Driver\Manager($config );
Copy after login

2. Simple statistics

$command = new \MongoDB\Driver\Command(['count' => $collection,'query'=>$filter]);
$result = $mongodb->executeCommand($db,$command);
Copy after login

Related recommendations:

How to operate the mongodb database in Node.js

PHP operates the MongoDB database

MongoDB database Commonly used operation PHP code

The above is the detailed content of How to operate MongoDB database in PHP (implementation of database connection and simple statistics). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template