Home  >  Article  >  Backend Development  >  PHP simple method to operate MongoDB (installation, addition, deletion, modification and query), mongodb addition and deletion_PHP tutorial

PHP simple method to operate MongoDB (installation, addition, deletion, modification and query), mongodb addition and deletion_PHP tutorial

WBOY
WBOYOriginal
2016-07-12 08:50:42886browse

How to simply operate MongoDB with PHP (installation, addition, deletion, modification and query), mongodb addition and deletion

This article describes the simple method of operating MongoDB with PHP. Share it with everyone for your reference, the details are as follows:

If you use PHP to operate MongoDB, first download the MongoDB expansion package from the Internet, https://github.com/mongodb/mongo-php-driver/downloads, and select the corresponding expansion package.

I downloaded this and unzipped it. VC6 is suitable for apache, VC9 is suitable for IIS, and ts (thread safe) means that PHP runs as a module.

Then put the php_mongo.dll in the ext folder in PHP, then add extension=php_mongo.dll to PHP.INI and restart apache.

The PHP extension MongoDB package is now installed.

For some functions of querying MongoDB, you can check the manual http://us.php.net/manual/en/class.mongocollection.php

<&#63;php
error_reporting(7);
$conn = new Mongo();
$db = $conn->PHPDataBase;
$collection = $db->PHPCollection;
/*-----------------------------
 * 删除
 *-----------------------------
$collection->remove(array("name" => "xixi111"));
*/
/*------------------------------
 * 插入
 *------------------------------
for($i = 0;$i <= 50;$i++) {
  $data = array("name" => "xixi".$i,"email" => "673048143_".$i."@qq.com","age" => $i*1+20);
  $collection->insert($data);
}
*/
/*-------------------------------
 * 查找
 *-------------------------------
$res = $collection->find(array("age" => array('$gt' => 25,'$lt' => 40)),array("name" => true));
foreach($res as $v) {
  print_r($v);
}
*/
/*-------------------------------
 * 更新
 *-------------------------------
 $collection->update(array("age" =>22),array('$set' => array("name" => "demoxixi")));
*/
&#63;>

Readers who are interested in more PHP-related content can check out the special topics of this site: "Complete PHP MongoDB database operation skills", "PHP based on pdo database operation skills summary", "php object-oriented programming introductory tutorial", "php Summary of String Usage", "Introduction Tutorial on PHP MySQL Database Operation" and "Summary of PHP Common Database Operation Skills"

I hope this article will be helpful to everyone in PHP programming.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1133084.htmlTechArticleHow to simply operate MongoDB with PHP (installation, addition, deletion, modification and check), mongodb addition and deletion. This article describes the simple operation of MongoDB with PHP. method. Share it with everyone for your reference, the details are as follows: php operation...
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