[MongoDB] mongodb and php, mongodbphp
Install mongodb php extension on windows
Https://s3.amazonaws.com/drivers.mongodb.org/php/index.html
Find the corresponding php version dll file, download php_cmd.dll, put it in the ext directory under the php installation directory, modify php. ini, and add an extension = php_cmd.dll. No php7-supported dll is found.
Get the publish client object, new
Obtain the database object database, and use the database attribute of the restore client object. For example, $ export client-> Database Name
Get the collection, and use the collection attribute of the db object, $ db-> Set Name
Create a collection and call the createCollection () method of the db object,
Call the find () method of the collection object to query data, $ collection-> find ()
Call the update () method of the collection object to update data, $ collection-> update ($ condition, $ data );
Call the insert () method of the collection object to insert data, $ collection-> insert ($ data );
<? Php // connect to mongodb $ mongoClient = new MongoClient (); // select a database $ db = $ mongoClient-> test; // obtain the 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 the document $ condition = array (); $ condition ['id'] = 2; $ collecti On-> remove ($ condition); // query the document $ users = $ collection-> find (); foreach ($ users as $ k => $ v) {print_r ($ v) ;}?>