Blogger Information
Blog 65
fans 1
comment 1
visits 118979
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
tp5.1 配置并使用MongoDB
技术宅的博客
Original
2395 people have browsed it

首先使用Mongo之前,需要装PHP的mongo扩展,访问 http://pecl.php.net/package/mongodb ,选择最新的版本即可,然后选择你的PHP版本对应的扩展。

然后使用Composer安装扩展包:

composer require topthink/think-mongo=2.0.*

在config 文件下创建一个名为mongdb.php 文件 配置如下

return [

	// 数据库类型
	'type'           => '\think\mongo\Connection',
	// 设置查询类
	'query'			 => '\think\mongo\Query',
	// 服务器地址
	'hostname'       => '127.0.0.1',
	// 集合名
	'database'       => 'red_package',
	// 用户名
	'username'       => '',
	// 密码
	'password'       => '',
	// 端口
	'hostport'       => '27017',
	// 强制把_id转换为id
	'pk_convert_id' => true,
];

配置完成后 基本操作如下 (详情查看手册tp5.1MongoDB使用

// 查询操作$user = Db::table('user')
	->where('_id','589461c0fc122812b4007411')
    ->find();// 或者直接使用$user = Db::table('user')
    ->find('589461c0fc122812b4007411');


Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post