PHP simple MongoDB operation method (installation, addition, deletion, modification, and query), mongodb addition and Deletion

Source: Internet
Author: User
Tags php mongodb

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"); */?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.