兰西源码网

兰西源码网

当前位置: PHP源码

叶辰萧初然最新章节在线阅读-php操作MongoDB基础教程(连接、新增、修改、删除、查询)

时间:2021-09-18来源:swan 作者:localhost 点击:

//连接叶辰萧初然最新章节在线阅读:27017

$conn = new Mongo();

$conn = new Mongo('test.com');

$conn = new Mongo('test.com:22011');

$conn = new Mongo("mongodb://${username}:${password}@叶辰萧初然最新章节在线阅读")

$conn = new Mongo("mongodb://${username}:${password}@叶辰萧初然最新章节在线阅读/blog");

$conn = new Mongo("mongodb://叶辰萧初然最新章节在线阅读:27017,叶辰萧初然最新章节在线阅读: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();


------分隔线----------------------------
栏目列表

推荐内容
热点内容