TP5+MONGODB usage Model

Source: Internet
Author: User
Tags mongodb
Model
<?php 
namespace App\index\model;
Use Think\model;
Class Test extends model{

}
Controller
<?php
namespace App\index\controller;
Use App\index\model\test;
Use Think\controller;
Use think\db;
Class Model extends controller{public
    function test () {
        $test = new test;
        $test->user_id= ' 0001 ';
        $test->user_name= ' Tuzi ';
        if ($test->save ()) {
            echo "success";
        } else{
            echo "error";
        }
        $res = db::table (' Test ')->select ();
        Dump ($res);
    }
Run Results
Success Array (5) {[0] => Array (3) {[' _id '] => object (Mongodb\bson\objectid) #20 (1) {[' oid '] => str
  ing () "5A522B025BFB248E032A9AB1"} ["user_id"] => string (4) "0001" ["User_name"] => string (4) "Tuzi" [1] => Array (3) {[' _id '] => object (Mongodb\bson\objectid) #21 (1) {[' oid '] => string (?) 5a522b4 C5bfb248dff003ea2 '} [' user_id '] => string (4) "0001" ["User_name"] => string (4) "Tuzi"} [2] => a Rray (3) {["_id"] => object (Mongodb\bson\objectid) #22 (1) {["OID"] => string () 5a522b505bfb248dff003ea 3 "} [" user_id "] => string (4)" 0001 "[" User_name "] => string (4)" Tuzi "} [3] => Array (3) {[" _id "] => object (Mongodb\bson\objectid) #23 (1) {[" OID] => string "5A522B515BFB248DFF003EA4"} ["U ser_id "] => string (4)" 0001 "[" User_name "] => string (4)" Tuzi "} [4] => Array (3) {[" _id "] => obje CT (Mongodb\bson\objectid) #24 (1) {["OID"] => string (5a522b575bfb248e012e17e1)} [user_id] => string (4) "0001" ["US Er_name "] => string (4)" Tuzi "}} 0.038957s Showpagetrace
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.