Home > php教程 > PHP开发 > body text

Simple method to operate MongoDB with PHP (installation, addition, deletion, modification and query)

高洛峰
Release: 2016-12-23 09:21:46
Original
1228 people have browsed it

The example in this article describes how to simply operate MongoDB with PHP. Share it with everyone for your reference, the details are as follows:

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

Simple method to operate MongoDB with PHP (installation, addition, deletion, modification and query)

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

Simple method to operate MongoDB with PHP (installation, addition, deletion, modification and query)

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

Now the PHP extension MongoDB package is installed.

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

<?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(&#39;$gt&#39; => 25,&#39;$lt&#39; => 40)),array("name" => true));
foreach($res as $v) {
  print_r($v);
}
*/
/*-------------------------------
 * 更新
 *-------------------------------
 $collection->update(array("age" =>22),array(&#39;$set&#39; => array("name" => "demoxixi")));
*/
?>
Copy after login

More PHP related articles on simple methods of operating MongoDB (installation, addition, deletion, modification and query) Please pay attention to PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!