PHP under the MONGODB Connection remote database detailed and case

Source: Internet
Author: User
This article mainly introduces the PHP under the remote database to connect to the code, the need for friends can refer to the following

WINDOWS Under-Loaded MongoDB

1. Create the data, logs folder, and mongo.conf in the MongoDB folder

Command-line command!

d:\mongodb\bin> mongod--dbpath D:\mongodb\data--logpath=d:\mongodb\logs\mongodb.log--logappend  D:\mongodb \bin>  Mongod-dbpath "d:\mongodb\data\db" d:\mongodb\bin> mongod--config "d:\mongodb\mongo.conf"

2, Configuration mongo.conf

Dbpath=d:\program files\mongodb\server\3.2\data #数据库路径 Logpath=d:\program Files\mongodb\server\3.2\logs\mongo.log # Log output file path logappend=true #错误日志采用追加模式 journal=true #启用日志文件, quiet=true #这个选项可以过滤掉一些无用的日志信息 enabled by default, set to False if debugging is required port= 27017 #端口号 defaults to 27017

3, the MONGO set as a service, easy to start later

Mongod--config "D:\Program files\mongodb\server\3.2\mongo.conf"--install--servicename "MongoDB" net start MongoDB

PHP connection

$conn = new Mongoclient ("Mongodb://xxx", Array (' username ' = ' username ', ' password ' = ' password ')); $db = $conn- >test; $collection = $db->test; $cursor = $collection->find (); foreach ($cursor as $id = + $value) {   echo "$id:"; Var_dump ($value); echo "<br>";    }

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.