In the past few days to participate in a creative marathon, although did not take any prize, the heavy participation
Finally have the opportunity to practice the MongoDB database, used to just own configuration to play
Here comes the wind.
Environment: WINDOW10 +php5.5.x+mysql5.7.x+mongodb2.6.x
Mongod installation 1. Download
Http://www.mongodb.org/downloads
I'm downloading the 64-bit msi here.
2. Installation
By default, you can
Default installation directory
C:\Program FILES\MONGODB 2.6 Standard\bin
3. Configuration
Save for D:\MONGODB.CNF
DBPath = D:\mongodb\databind_ip = 127.0.0.1port = 27017quiet = Truelogpath = D:\mongodb\log\mongod.loglogappend = Truejour NAL = True
4. Start
This is the use of Bat batch start, easy.
Here's the boot. bat
C \ "program Files" \ "MongoDB 2.6 standard" \bin\mongod.exe-f d:\mongodb.cnf
If you are building system services (you do not need to restart the database every time you shut down your computer), use
C \ "program Files" \ "MongoDB 2.6 standard" \bin\mongod.exe--config d:\mongodb.cnf--install
5. Database User name password
Database user name and password are empty by default after successful startup
PHP Mongod Extended Installation
Download: http://download.csdn.net/detail/dupingjin/7577217
Choose the appropriate extension based on the PHP version, which is used here
Php_mongo-1.4.5-5.5-vc11-nts.dll
Into
PHPDirectory
extfolder under
Modify PHP.ini
Extension the end of a line or php.ini.
Extension=php_mongo-1.4.5-5.5-vc11-nts.dll
Restarting the Php/nginx/apache environment
Test output to see if there are MONGO this environment parameter in Phpinfo, there is the installation success!
Test
<?phpheader ("Content-type:text/html;charset=utf-8"); $m = new Mongoclient ("mongodb://127.0.0.1:27017");// If the patent database does not exist, the default auto new $db = $m->patent;//If the title table does not exist, the default auto new $collection = $db->title;echo '
PHP mongod Delete and change query1. Add$m = new Mongoclient ("mongodb://127.0.0.1:27017");//If the Lanmps database does not exist, the default auto new $db = $m->lanmps;//If the title table does not exist, the default auto new $ Collection = $db->title; $add = ["title" = "Www.lanmps.com", "Author" = "Wind"]; $result = $collection->insert ($add); Add $add to the $collection collection echo "New record ID:". $add [' _id ']; #MongoDB会返回一个记录标识var_dump ($result); #返回: BOOL (TRUE)
2. Modify the Update$m = new Mongoclient ("mongodb://127.0.0.1:27017");//If the Lanmps database does not exist, the default auto new $db = $m->lanmps;//If the title table does not exist, the default auto new $ Collection = $db->title; $where = ["title" = "Test.lanmps.com", "Author" = "Wind", "id" =>new MongoId (' 3sdfasf ZXCV234234SF ')]; $coll->update (["Host" = "www.lanmps.com"], [' $set ' + $where]);
3. Delete$m = new Mongoclient ("mongodb://127.0.0.1:27017");//If the Lanmps database does not exist, the default auto new $db = $m->lanmps;//If the title table does not exist, the default auto new $ Collection = $db->title; $where = ["title" = "Www.lanmps.com", "Author" = "Wind", "id" =>new MongoId (' 3sdfasfz XCV234234SF ')];//delete $collection->remove ($where);
4. Enquiry$m = new Mongoclient ("mongodb://127.0.0.1:27017");//If the Lanmps database does not exist, the default auto new $db = $m->lanmps;//If the title table does not exist, the default auto new $ Collection = $db->title; $where = ["title" = "Www.lanmps.com", "Author" = "Wind", "id" =>new MongoId (' 3sdfasfz XCV234234SF ')];//find a $cursor= $collection->findone ($where, [' title ', ' Author ', ' text ']); Var_dump ($cursor);//Find Multiple $cursor = $collection->find ($where); Var_dump ($cursor);
$m = new Mongoclient ("mongodb://127.0.0.1:27017");//If the Lanmps database does not exist, the default auto new $db = $m->lanmps;//If the title table does not exist, the default auto new $ Collection = $db->title; $where = ["title" = "Www.lanmps.com", "Author" = "Wind", "id" =>new MongoId (' 3sdfasfz XCV234234SF ')];/** query Record Count **/echo $collection->count (); #全部echo ' <br/> '; Echo $collection->count ($where); #可以加上条件echo ' <br/> '; echo $collection->count ([' Day ' =>[' $gt ' =>10, ' $lte ' =>20]]); #大于10小于等于20echo ' <br/> ';//limit display 5, starting from No. 0 echo $collection->find ()->limit (5)->skip (0)->count ( true); #获得实际返回的结果数//Note: $GT is greater than, $GTE is greater than or equal to, $lt is less than, $lte is less than or equal, $ne is not equal to, $exists does not exist
Fuzzy query
$querys = ["name"] = new Mongoregex ("/*.asdfsf*./$i")]; $collection->find ($querys);
Windows PHP MongoDB installation configuration using queries