Thinkphp with MongoDB

Source: Internet
Author: User

First, add a database connection with MongoDB in config.php
  
 
  1. ‘DB_TYPE‘=>‘mongo‘,// 数据库类型
  2. ‘DB_HOST‘=>‘localhost‘,// 服务器地址
  3. ‘DB_NAME‘=>‘fzdb‘,// 数据库名
  4. ‘DB_USER‘=>‘‘,// 用户名
  5. ‘DB_PWD‘=>‘‘,// 密码
  6. ‘DB_PORT‘=>27017,// 端口
  7. ‘DB_PREFIX‘=>‘fz_‘,// 数据库表前缀
  8. ‘DB_CHARSET‘=>‘utf8‘,// 数据库字符集

indexcontroller.class.php Create a MongoDB module inside the controller
 
   
  
  1. \Think\Build::buildModel(‘Home‘, ‘Student‘);
Then go to the model and modify the file.
  
 
  1. <?php
  2. namespace Home\Model;
  3. use Think\Model\MongoModel;
  4. class StudentModel extends MongoModel {
  5. }
Querying data

MongoDB Database Add information
  
 
  1. $m=D(‘student‘);
  2. //添加数据信息
  3. $d[‘sname‘]=‘张三丰‘;
  4. $m->add($d);
MongoDB database query Information
 
   
  
  1. $m=D(‘student‘);
  2. $rs=$m->select();
  3. dump($rs);
$rs = $m->field (' sname ')->select ();
Field fields name modify data information by ID with Save
  
 
  1. //修改数据信息
  2. $d[‘_id‘]=‘559c983564f7676816000029‘;
  3. $d[‘sname‘]=‘连少蕊‘;
  4. $m->save($d);
Deletes the specified information by ID
 
   
  
  1. //删除指定的id
  2. $m->delete(‘559c984264f767d00b000029‘);







From for notes (Wiz)

Thinkphp with MongoDB

Related Article

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.