[MongoDB] MongoDB and php,mongodbphp_php tutorial

Source: Internet
Author: User
Tags install mongodb mongoclient

[MongoDB] MongoDB and php,mongodbphp


Installing MongoDB PHP extensions 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, put in the PHP installation directory in the EXT directory, modify the php.ini, add a extension=php_mongo.dll, did not find support PHP7 DLL

Get Mongoclient object, new out

Gets the database object db, through the database properties of the Mongoclient object, $MongoClient database name

Gets the collection collection, by the collection property of the DB object, $db the collection name

Creates a collection that invokes the CreateCollection () method of the DB object,

Call the Find () method of the collection object, query the data, $collection->find ()

Calls the update () method of the collection object, updates the data, $collection->update ($condition, $data);

Call the Insert () method of the collection object, insert the data, $collection->insert ($data);

 Php//Connect to MongoDB$mongoClient=Newmongoclient ();//Select a database$db=$mongoClient-test;//Get Collection$collection=$db-users;//Update 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 a document$condition=Array();$condition[' ID ']=2;$collection->remove ($condition);//Querying documents$users=$collection-find ();foreach($users  as $k=$v) {    Print_r($v);}?>

http://www.bkjia.com/PHPjc/1122396.html www.bkjia.com true http://www.bkjia.com/PHPjc/1122396.html techarticle [MongoDB] MongoDB with php,mongodbphp install MongoDB PHP extension download address on Windows https://s3.amazonaws.com/drivers.mongodb.org/php /index.html find the corresponding PHP version of the DLL file, ...

  • 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.