PHP extensions for MongoDB installed on Windows
Download Address https://s3.amazonaws.com/drivers.mongodb.org/php/index.html
Find the corresponding PHP version of the DLL file, download php_mongo.dll
, placed in the PHP installation directory in the EXT directory, modify php.ini, add an item extension=php_mongo.dll
, did not find support for PHP7 DLL
- Get Mongoclient object, new out
- Get database object db, $MongoClient-> database name by mongoclient the database properties of the object
- Gets the collection collection, through the collection property of the DB object, $db-> collection name
- Creates a collection that invokes the CreateCollection () method of the DB object,
- Call the Collection object's Find () method, query the data, $collection->find ()
- Call the update () method of the collection object, update the data, $collection->update ($condition, $data);
- Invokes the Insert () method of the collection object, inserting the data, $collection->insert ($data);
<?php//connect to MongoDB $mongoClient = new Mongoclient ();//Select a database $db = $mongoClient-&G
T;test;
Get collection $collection = $db->users;
Update the document $condition =array ();
$condition ["id"]=1;
$data =array ();
$data [' name ']= ' Wangwu ';
$data [' Age ']= ' 11];
$collection->update ($condition, $data);
Insert Document $data =array ();
$data [' id ']=4;
$data [' name ']= ' haha];
$data [' Age ']= ' 11];
$collection->insert ($data);
Delete Document $condition =array ();
$condition [' id ']=2;
$collection->remove ($condition);
Query document $users = $collection->find (); foreach ($users as $k => $v) {print_r ($v);}?>