PHP simple MongoDB operation method (installation, addition, deletion, modification, and query), mongodb addition and Deletion
This article describes how to operate MongoDB in PHP. We will share this with you for your reference. The details are as follows:
For php operations on MongoDB, first download the MongoDB extension package from the Internet, https://github.com/mongodb/developer-php-driver/downloads, and select the corresponding expansion package.
This is my example, and decompress it. VC6 is suitable for apache, VC9 is suitable for IIS, and ts (thread safe) means PHP runs in the form of modules.
Put php_cmd.dll In the ext folder of PHP, add extension = php_cmd.dll to PHP. INI, and restart apache.
So far, the PHP MongoDB extension package has been installed.
About querying MongoDB some use functions can be queried manual http://us.php.net/manual/en/class.mongocollection.php
<? Phperror_reporting (7); $ conn = new Mongo (); $ db = $ conn-> PHPDataBase; $ collection = $ db-> PHPCollection; /* ----------------------------- * Delete * ----------------------------- $ collection-> remove (array ("name" => "xixi111 ")); * // * ------------------------------ * Insert * -------------------------------- for ($ I = 0; $ I <= 50; $ I ++) {$ data = array ("name" => "xixi ". $ I, "email" => "673048143 _". $ I. "@ qq.com", "age" => $ I * 1 + 20 ); $ Collection-> insert ($ data );} * // * --------------------------------- * search for * ------------------------------- $ res = $ collection-> find (array ("age" => array ('$ gt' => 25, '$ lt' => 40), array ("name" => true); foreach ($ res as $ v) {print_r ($ v );} * // * --------------------------------- * update * --------------------------------- $ collection-> update (array ("age" => 22 ), array ('$ set' => array ("name" => "demoxixi"); */?>