search
Homephp教程php手册thinkphp mysql和mongodb 完美使用

thinkphp mysql和mongodb 完美使用。
第一步:在你的应用的Model文件下建立一个MonModel如下图
thinkphp mysql和mongodb 完美使用
第二步:MonModel的内容如下
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2015/12/16
* Time: 15:29
*/
namespace Admin\Model;
use Think\Model\MongoModel;
Class MonModel extends MongoModel
{
public function __construct($name, $tablePrefix, $connection)
{
parent::__construct($name, $tablePrefix, $connection);
$this->trueTableName=$name;//要连接的那个集合(表)控制器里传过来
}
protected $dbName='name';//(要连接的数据库名称)
protected $connection = array(
'db_type' => 'mongo',
'db_user' => 'admin',//用户名(没有留空)
'db_pwd' => 'admin',//密码(没有留空)
'db_host' => '127.0.0.1',//数据库地址
'db_port' => '27017',//数据库端口 默认27017
);
protected $_idType = self::TYPE_INT; //参考手册
protected $_autoinc = true;//参考手册
/* public function getall()
{
return $this->select();
}*/
}
第三步:你就可以在你的控制器里用这个MonModel去操作mongodb了。
如下
namespace Admin\Controller;
use Admin\Model\MonModel;
use Common\Controller\YouKangController;
class AuController extends YouKangController {
public function index()
{
$M= new MonModel('movie');//movie是集合名(表名)
diedump($M->select());
}
}

AD:真正免费,域名+虚机+企业邮箱=0元

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version