无为清净楼资源网 Design By www.qnjia.com

复制代码 代码如下:
//连接localhost:27017
$conn = new Mongo();

//连接远程主机默认端口
$conn = new Mongo('test.com');

//连接远程主机22011端口
$conn = new Mongo('test.com:22011');

//MongoDB有用户名密码
$conn = new Mongo("mongodb://${username}:${password}@localhost")

//MongoDB有用户名密码并指定数据库blog
$conn = new Mongo("mongodb://${username}:${password}@localhost/blog");

//多个服务器
$conn = new Mongo("mongodb://localhost:27017,localhost:27018");
//选择数据库blog
$db = $conn->blog;
//制定结果集(表名:users)
$collection = $db->users;
//新增
$user = array('name' => 'caleng', 'email' => 'admin#admin.com');
$collection->insert($user);
//修改
$newdata = array('$set' => array("email" => "test@test.com"));
$collection->update(array("name" => "caleng"), $newdata);
//删除
$collection->remove(array('name'=>'caleng'), array("justOne" => true));
//查找
$cursor = $collection->find();
var_dump($cursor);
//查找一条
$user = $collection->findOne(array('name' => 'caleng'), array('email'));
var_dump($user);
//关闭数据库
$conn->close();

标签:
php,MongoDB

无为清净楼资源网 Design By www.qnjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
无为清净楼资源网 Design By www.qnjia.com