模型
<?php
namespace app \index \model ;
use think \Model ;
class Test extends Model {
}
控制器
<?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 );
}
}
运行结果
success
array (5 ) {
[0 ] => array (3 ) {
["_id" ] => object(MongoDB\BSON\ObjectId)
["oid" ] => string(24 ) "5a522b025bfb248e032a9ab1"
}
["user_id" ] => string(4 ) "0001"
["user_name" ] => string(4 ) "tuzi"
}
[1 ] => array (3 ) {
["_id" ] => object(MongoDB\BSON\ObjectId)
["oid" ] => string(24 ) "5a522b4c5bfb248dff003ea2"
}
["user_id" ] => string(4 ) "0001"
["user_name" ] => string(4 ) "tuzi"
}
[2 ] => array (3 ) {
["_id" ] => object(MongoDB\BSON\ObjectId)
["oid" ] => string(24 ) "5a522b505bfb248dff003ea3"
}
["user_id" ] => string(4 ) "0001"
["user_name" ] => string(4 ) "tuzi"
}
[3 ] => array (3 ) {
["_id" ] => object(MongoDB\BSON\ObjectId)
["oid" ] => string(24 ) "5a522b515bfb248dff003ea4"
}
["user_id" ] => string(4 ) "0001"
["user_name" ] => string(4 ) "tuzi"
}
[4 ] => array (3 ) {
["_id" ] => object(MongoDB\BSON\ObjectId)
["oid" ] => string(24 ) "5a522b575bfb248e012e17e1"
}
["user_id" ] => string(4 ) "0001"
["user_name" ] => string(4 ) "tuzi"
}
}
0.038957 s ShowPageTrace