MongoDB First Experience

Source: Internet
Author: User
Tags md5

This morning to find information, found MongoDB, free to study the next, I use the Phpstudy integration package to add MongoDB extension.

1. Add MONGO, MongoDB extension

Phpstudy integrated environment is generally 32-bit PHP, go to the official website to download 32-bit MONGO, MongoDB extension

Mongo:http://pecl.php.net/package/mongo

Mongodb:http://pecl.php.net/package/mongodb

Select the extension library that is relative to your PHP version and download it, unzip the file to copy the. dll file into the PHP ext directory, and add the following two lines to the php.ini file:

Extension=php_mongo.dll

Extension=php_mongodb . DLL

Restart the Phpstudy environment, visit the Phpinfo () page, see the MONGO, MongoDB extension to indicate that the installation was successful.

2.mongodb additions and deletions to search

A. Link MongoDB   

$conn = new Mongoclient ();//Do not write parameter is with local MongoDB, ' localhost:27017 ', remote server write remote address and port $alldb = $conn->listdbs ();//var_ Dump ($ALLDB); To see if there is a return structure, there is an indication that the connection is successful. $db = $conn->demo; Select the database and automatically create $collection = $db If it does not exist->test; The collection is equivalent to a data table and is automatically created if it does not exist

B.curd Operation

1 //Inserting Data2 $insertArray=Array(' id ' = =Rand(1,50), ' name ' = ' admin ', ' pwd ' =MD5("123456"));//format is the array's key (column) and value (column value)3 $insertRes=$collection->insert ($insertArray);4 5 //get all the data6 $where=Array("id" =Array(' $gt ' =>20));//where you can query the condition is also in the form of an array7 $selectDb=$collection->find ($where)->fields (Array(' name ' = =true, ' pwd ' =true));8 $array=Array();9 foreach($selectDb  as $id=$value) {Ten     $array[] =$value; One } A  - //get a piece of data - $selectOne=$collection-FindOne (); the  - //Update Data - $sign=Array("Name" = ' admin '); - $param=Array("Name" = ' admin888 ', ' pwd ' =MD5(' 12345 ')); + $updateRes=$collection->update ($sign,$param); -  + //Delete Data A $collection->remove (Array(' name ' = ' HM ')); , delete the specified condition data at $conn-Dropdb (' demo ');//Delete a library - $collection->remove ();//Empty collection (delete all data) -  - //Disconnect MongoDB connection - $m->close ();

Other information:

Http://www.cnblogs.com/wangwanchao/p/5807630.html

http://blog.csdn.net/cdnight/article/details/49557795

Http://www.cnblogs.com/cswuyg/p/4595799.html

http://blog.csdn.net/qinshi501/article/details/52932232

  

MongoDB First Experience

Related Article

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.