mongodb+php implementation of simple addition deletion change and check
- 2020-05-30 21:14:45
- OfStack
Install the php extension of mongodb on windows
Download address https: / / s3. amazonaws. com/drivers mongodb. org/php/index html
Find the corresponding php version of dll file and download it
php_mongo.dll
, put it in the ext directory under the php installation directory, modify php.ini, and add 1 item
extension=php_mongo.dll
, dll support for php7 was not found
<?php
// Connect to the mongodb
$mongoClient = new MongoClient();
// choose 1 A database
$db = $mongoClient->test;
// For collection
$collection=$db->users;
// Update the document
$condition=array();
$condition["id"]=1;
$data=array();
$data['name']="wangwu";
$data['age']="11";
$collection->update($condition,$data);
// Inserted into the document
$data=array();
$data['id']=4;
$data['name']=" Ha ha ";
$data['age']="11";
$collection->insert($data);
// Delete the document
$condition=array();
$condition['id']=2;
$collection->remove($condition);
// Query the document
$users=$collection->find();
foreach ($users as $k => $v) {
print_r($v);
}
?>