[MongoDB] mongodb and php, mongodbphp

Source: Internet
Author: User

[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) ;}?>

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.