Home  >  Article  >  Backend Development  >  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)

不言
不言Original
2018-08-23 09:51:181925browse

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!

Statement:
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