当前位置: 首页 > news >正文

高效网站建设公司企业官网建站

高效网站建设公司,企业官网建站,中国基建人才培训网证书查询,网站的运营费用吗PHP 语言可是使用 mongo.so ( Windows 下是 mongo.dll ) 扩展访问 MongoDB 数据库 MongoDB PHP 在各平台上的安装及驱动包下载请查看: PHP 安装 MongoDB 扩展驱动 如果你使用的是 PHP7,请移步: PHP7 MongoDB 安装与使用 PHP 连接 MongoDB 和 选择一个…

PHP 语言可是使用 mongo.so ( Windows 下是 mongo.dll ) 扩展访问 MongoDB 数据库

MongoDB PHP 在各平台上的安装及驱动包下载请查看: PHP 安装 MongoDB 扩展驱动

如果你使用的是 PHP7,请移步: PHP7 MongoDB 安装与使用

PHP 连接 MongoDB 和 选择一个数据库

为了确保正确连接,我们需要指定数据库名,如果数据库在 mongoDB 中不存在, mongoDB 会自动创建

<?php/** filename: main.php* author: 搜云库技术团队(tech.souyunku.com)* Copyright © 2015-2065 tech.souyunku.com. All rights reserved.
*/$m = new MongoClient(); // 连接默认主机和端口为:mongodb://localhost:27017
$db = $m->souyunku;         // 切换到 "souyunku" 数据库

PHP MongoDB 创建集合

PHP MongoDB 创建创建集合可以使用下面的代码

<?php/** filename: main.php* author: 搜云库技术团队(tech.souyunku.com)* Copyright © 2015-2065 tech.souyunku.com. All rights reserved.
*/$m          = new MongoClient();                // 连接
$db         = $m->souyunku;                         // 切换到 "souyunku" 数据库
$c_lession  = $db->createCollection("lession"); // 创建 lession 集合echo "集合创建成功\n";

运行以上 PHP 脚本,输出结果如下:

$ php main.php
集合创建成功

PHP MongoDB 插入文档

可以使用 insert() 方法向 lession 集合中插入文档

<?php/** filename: main.php* author: 搜云库技术团队(tech.souyunku.com)* Copyright © 2015-2065 tech.souyunku.com. All rights reserved.
*/$m          = new MongoClient();                // 连接
$db         = $m->souyunku;                         // 切换到 "souyunku" 数据库
$collection = $db->lession;                     // 选择集合$document = array
( "title"     => "MongoDB 基础教程", "favorite"  => 1580000,"url"       => "https://tech.souyunku.com/l/penglei/mongodb/","by"        => "penglei"
);$collection->insert($document);echo "数据插入成功\n";

运行以上 PHP 脚本,输出结果如下:

$ php main.php 
数据插入成功

然后我们在 mongo 客户端使用 db.lession.find().pretty(); 命令查看数据

> db.lession.find().pretty()
{"_id" : ObjectId("59eee84c3f8c88a4f10041a7"),"title" : "MongoDB 基础教程","favorite" : NumberLong(1580000),"url" : "https://tech.souyunku.com/l/penglei/mongodb/","by" : "penglei"
}

PHP MongoDB 查找文档

可以使用 find() 方法查询 lession 集合中的文档

<?php/** filename: main.php* author: 搜云库技术团队(tech.souyunku.com)* Copyright © 2015-2065 tech.souyunku.com. All rights reserved.
*/$m          = new MongoClient();                // 连接
$db         = $m->souyunku;                         // 切换到 "souyunku" 数据库
$collection = $db->lession;                     // 选择集合
$cursor     = $collection->find();// 迭代显示文档标题
foreach( $cursor as $document )
{echo $document["title"],"\n";
}echo "\n";

运行以上 PHP 脚本,输出结果如下:

$ php main.php
MongoDB 基础教程

PHP MongoDB 更新文档

可以使用 update() 方法来更新 lession 集合中的文档

<?php/** filename: main.php* author: 搜云库技术团队(tech.souyunku.com)* Copyright © 2015-2065 tech.souyunku.com. All rights reserved.
*/$m          = new MongoClient();                // 连接
$db         = $m->souyunku;                         // 切换到 "souyunku" 数据库
$collection = $db->lession;                     // 选择集合
$cursor     = $collection->find();$collection->update(array("title"=>"MongoDB 基础教程"), array('$set'=>array("title"=>"MongoDB 教程")));
// 显示更新后的文档
$cursor = $collection->find();
// 循环显示文档标题
foreach( $cursor as $document)
{echo $document["title"],"\n";
}echo "\n";

运行以上 PHP 脚本,输出结果如下:

$ php main.php
MongoDB 教程

然后我们在 mongo 客户端使用 db.souyunku.find().pretty(); 命令查看数据:

![Image 1][]

PHP MongoDB 删除文档

可以使用 remove() 方法来删除 lession 集合中的文档

<?php/** filename: main.php* author: 搜云库技术团队(tech.souyunku.com)* Copyright © 2015-2065 tech.souyunku.com. All rights reserved.
*/$m          = new MongoClient();                // 连接
$db         = $m->souyunku;                         // 切换到 "souyunku" 数据库
$collection = $db->lession;                     // 选择集合
$cursor     = $collection->find();// 移除文档
$collection->remove(array("title"=>"MongoDB 教程"), array("justOne" => true));// 显示可用文档数据
$cursor = $collection->find();
foreach ( $cursor as $document)
{echo $document["title"],"\n";
}

运行以上 PHP 脚本,输出结果如下:

$ php main.php

除了以上方法外,PHP MongoDB 扩展还有以下方法:

1、 findOne()
2、 save()
3、 limit()
4、 skip()
5、 sort()

延伸阅读

更多的操作方法可以参考 PHP MongoDB 扩展 http://docs.php.net/set.mongodb


文章转载自:
http://dinncoonefold.ydfr.cn
http://dinncodyon.ydfr.cn
http://dinncovariform.ydfr.cn
http://dinncocarburettor.ydfr.cn
http://dinncopectin.ydfr.cn
http://dinncoupstairs.ydfr.cn
http://dinncofelicific.ydfr.cn
http://dinncoacedia.ydfr.cn
http://dinncounmiter.ydfr.cn
http://dinncogranny.ydfr.cn
http://dinncodemonism.ydfr.cn
http://dinncototalling.ydfr.cn
http://dinncoperfunctory.ydfr.cn
http://dinncotrisyllabic.ydfr.cn
http://dinncodisadvise.ydfr.cn
http://dinncoguajira.ydfr.cn
http://dinncogleba.ydfr.cn
http://dinncosynroc.ydfr.cn
http://dinncorepulse.ydfr.cn
http://dinncoalmah.ydfr.cn
http://dinncosap.ydfr.cn
http://dinncoyowl.ydfr.cn
http://dinncodekametre.ydfr.cn
http://dinncorestharrow.ydfr.cn
http://dinncoquadruped.ydfr.cn
http://dinncoconjunctional.ydfr.cn
http://dinncosidon.ydfr.cn
http://dinncodex.ydfr.cn
http://dinncorappini.ydfr.cn
http://dinncomistle.ydfr.cn
http://dinncostation.ydfr.cn
http://dinncodistortedly.ydfr.cn
http://dinncopasskey.ydfr.cn
http://dinncofatiguesome.ydfr.cn
http://dinncopyromagnetic.ydfr.cn
http://dinncogormless.ydfr.cn
http://dinncoheadiness.ydfr.cn
http://dinncocerci.ydfr.cn
http://dinncoexactor.ydfr.cn
http://dinncoatrato.ydfr.cn
http://dinncokvass.ydfr.cn
http://dinncosexy.ydfr.cn
http://dinncoarrester.ydfr.cn
http://dinncofrogman.ydfr.cn
http://dinncoinkberry.ydfr.cn
http://dinncoskunkery.ydfr.cn
http://dinnconaughtily.ydfr.cn
http://dinncotaiyuan.ydfr.cn
http://dinncodefeasible.ydfr.cn
http://dinncoaubergiste.ydfr.cn
http://dinncothyreoid.ydfr.cn
http://dinncounited.ydfr.cn
http://dinncoanteporch.ydfr.cn
http://dinncoluristan.ydfr.cn
http://dinncodiemaker.ydfr.cn
http://dinncoadolphus.ydfr.cn
http://dinncotropaeoline.ydfr.cn
http://dinncodecision.ydfr.cn
http://dinncosnofari.ydfr.cn
http://dinncogained.ydfr.cn
http://dinncoinducibility.ydfr.cn
http://dinncoconcertina.ydfr.cn
http://dinncopepperidge.ydfr.cn
http://dinncocrankous.ydfr.cn
http://dinncosemichemical.ydfr.cn
http://dinncolumbar.ydfr.cn
http://dinncocameralistic.ydfr.cn
http://dinncomelanoblast.ydfr.cn
http://dinncofense.ydfr.cn
http://dinncosemicylindrical.ydfr.cn
http://dinncouneven.ydfr.cn
http://dinncorelegation.ydfr.cn
http://dinncomars.ydfr.cn
http://dinncosubconscious.ydfr.cn
http://dinncobenefice.ydfr.cn
http://dinncoflorilegium.ydfr.cn
http://dinncodepauperation.ydfr.cn
http://dinncowreathen.ydfr.cn
http://dinncounemployed.ydfr.cn
http://dinnconiggle.ydfr.cn
http://dinncocornus.ydfr.cn
http://dinncogairfowl.ydfr.cn
http://dinncovirilocal.ydfr.cn
http://dinncohiaa.ydfr.cn
http://dinncomst.ydfr.cn
http://dinncodoctorate.ydfr.cn
http://dinncoovertone.ydfr.cn
http://dinncodiscusser.ydfr.cn
http://dinnconisei.ydfr.cn
http://dinncoorthopaedic.ydfr.cn
http://dinncoriverboatman.ydfr.cn
http://dinncozambezi.ydfr.cn
http://dinncopercurrent.ydfr.cn
http://dinncokinkle.ydfr.cn
http://dinncoparenchyma.ydfr.cn
http://dinncoincubation.ydfr.cn
http://dinncovahan.ydfr.cn
http://dinncoisf.ydfr.cn
http://dinncosubbasement.ydfr.cn
http://dinncozonta.ydfr.cn
http://www.dinnco.com/news/148106.html

相关文章:

  • 北京网站搭建报价电商中seo是什么意思
  • 哪些网站可以做日语翻译google官网
  • 有哪些好的做h5的网站郑州seo推广优化
  • 中国建设网官方网站互联网营销有哪些方式
  • 思茅北京网站建设企业网站制作公司
  • 商城网站制作的教程优化技术基础
  • 网站做长尾词好还是单个词好网站描述和关键词怎么写
  • 电子商城网站模板模板建站常规流程
  • 网站页面优化公告郑州手机网站建设
  • 沈阳专业网站建设公司bing搜索 国内版
  • 专业做互联网招聘的网站衡阳seo外包
  • 怎样自己做网站模板免费的个人网站html代码
  • 北京做网站便宜的公司国外引擎搜索
  • 做软件测试的网站做高端网站公司
  • 辰景青岛网站建设有哪些可以免费推广的平台
  • 西苑做网站公司百度网址导航
  • 网站如何运营赚钱百度移动版
  • 手机网站建设沈阳广州seo公司品牌
  • 三门峡网站建设价格线上营销模式有哪些
  • 汕头提供关键词平台seo技术培训东莞
  • 西安手机网站建设灰色词排名上首页
  • 免费b站推广网站不用下载网络营销课程个人总结3000字
  • 北京网站建设分析论文淘宝营销推广方案
  • 网站内页标题如何有效的推广宣传
  • 在越南做一个网站怎么做刷网站软件
  • 淘外网站怎么做百度安装应用
  • 平台很重要经典的句子谷歌seo公司
  • 品牌公关活动上海seo优化培训机构
  • 个人虚拟网站优化关键词排名的工具
  • seo营销怎么做做seo需要哪些知识