Home > Article > Backend Development > How to operate MongoDB database in PHP (implementation of database connection and simple statistics)
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 );
2. Simple statistics
$command = new \MongoDB\Driver\Command(['count' => $collection,'query'=>$filter]); $result = $mongodb->executeCommand($db,$command);
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!