Today, using thinkPHP to operate MongoDB found that there are many differences between using MYSQL and sharing with you here. I
am temporarily useless. ThinkPHP5 has been using thinkPHP3.2.3 and it feels very useful. MongoDB versions 2 and 3 have passed the test
. php
// Connect to mongoDB ' DB_TYPE ' => 'mongo', // database type 'DB_HOST' => '127.0.0.1', // server address 'DB_NAME' => 'local', // database name 'DB_USER' => '', // username 'DB_PWD' => '', // password 'DB_PORT' => '27017', // port 'DB_CHARSET' => 'utf8', // database encoding 'DB_DEBUG' => false, // The SQL log can be recorded after the database debugging mode is turned on
IndexController.class.php
//http://localhost/testmdb/Index/xiugai/name/张雷帅哥 //改 public function xiugai($name=''){ $db = D("Col"); $data['reg'] = '20170310'; $returl = $db ->where(array("name"=>$name)) ->save($data); var_dump($returl); } //http://localhost/testmdb/Index/shan/id/58c2483e4b1486d073000032 //删 public function shan($id=''){ $db = D("Col"); $returl = $db ->where(array("_id"=>$id)) ->delete(); var_dump($returl); } }
ColModel.class.php
<?php namespace Home\Model; use Think\Model\MongoModel; Class ColModel extends MongoModel{ }