php moungoDB

moungoDB 语法

SQL查询语句    Mongo查询语句
CREATE TABLE USERS (a Number, b Number)     隐式的创建,或 MongoDB::createCollection().
INSERT INTO USERS VALUES(1,1)    $db->users->insert(array("a" => 1, "b" => 1));
SELECT a,b FROM users    $db->users->find(array(), array("a" => 1, "b" => 1));
SELECT * FROM users WHERE age=33    $db->users->find(array("age" => 33));
SELECT a,b FROM users WHERE age=33    $db->users->find(array("age" => 33), array("a" => 1, "b" => 1));
SELECT a,b FROM users WHERE age=33 ORDER BY name    $db->users->find(array("age" => 33), array("a" => 1, "b" => 1))->sort(array("name" => 1));
SELECT * FROM users WHERE age>33    $db->users->find(array("age" => array(‘$gt‘ => 33)));
SELECT * FROM users WHERE age<33    $db->users->find(array("age" => array(‘$lt‘ => 33)));
SELECT * FROM users WHERE name LIKE "%Joe%"    $db->users->find(array("name" => new MongoRegex("/Joe/")));
SELECT * FROM users WHERE name LIKE "Joe%"    $db->users->find(array("name" => new MongoRegex("/^Joe/")));
SELECT * FROM users WHERE age>33 AND age<=40    $db->users->find(array("age" => array(‘$gt‘ => 33, ‘$lte‘ => 40)));
SELECT * FROM users ORDER BY name DESC    $db->users->find()->sort(array("name" => -1));
CREATE INDEX myindexname ON users(name)    $db->users->ensureIndex(array("name" => 1));
CREATE INDEX myindexname ON users(name,ts DESC)    $db->users->ensureIndex(array("name" => 1, "ts" => -1));
SELECT * FROM users WHERE a=1 and b=‘q‘    $db->users->find(array("a" => 1, "b" => "q"));
SELECT * FROM users LIMIT 20, 10    $db->users->find()->limit(10)->skip(20);
SELECT * FROM users WHERE a=1 or b=2    $db->users->find(array(‘$or‘ => array(array("a" => 1), array("b" => 2))));
SELECT * FROM users LIMIT 1    $db->users->find()->limit(1);
EXPLAIN SELECT * FROM users WHERE z=3    $db->users->find(array("z" => 3))->explain()
SELECT DISTINCT last_name FROM users    $db->command(array("distinct" => "users", "key" => "last_name"));
SELECT COUNT(*y) FROM users    $db->users->count();
SELECT COUNT(*y) FROM users where AGE > 30    $db->users->find(array("age" => array(‘$gt‘ => 30)))->count();
SELECT COUNT(AGE) from users    $db->users->find(array("age" => array(‘$exists‘ => true)))->count();
UPDATE users SET a=1 WHERE b=‘q‘    $db->users->update(array("b" => "q"), array(‘$set‘ => array("a" => 1)));
UPDATE users SET a=a+2 WHERE b=‘q‘    $db->users->update(array("b" => "q"), array(‘$inc‘ => array("a" => 2)));
DELETE FROM users WHERE z="abc"    $db->users->remove(array("z" => "abc"));

会员反馈功能

web  leaf/leaf/feedback.php

<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <link rel="stylesheet" type="text/css" href="<?php echo assets(TPLURL . "assets/css/bootstrap.min.css") ;?>"/>
    <link rel="stylesheet" type="text/css" href="<?php echo assets(TPLURL . "assets/css/mobile-style.css") ;?>">
    <link rel="stylesheet" type="text/css" href="<?php echo assets(TPLURL . "assets/css/sweetalert.css") ;?>">
    <title></title>
</head>
<body>
<header class="personal_center_header">
    <div >
        <a href="#" ><i><img src="<?php echo TPLURL ;?>assets/img/1_03.png" alt="" /></i><p>意见反馈</p><img src="<?php echo TPLURL ;?>assets/img/1_03.gif" alt=""/></a>
    </div>
</header>
<article class="feedback_article apply_agent_article">
    <form id="form-feedback">
        <label><small>请留下您宝贵的意见</small></label>
        <textarea  placeholder="您想对我们说点什么......" name="explain" id="explain"></textarea>
        <div class="address">
            <small>付款截图上传</small>
            <p>
                <input type="file" name="pic" id="pic" class="file"/>
                <strong>浏览图片</strong>
            </p>
        </div>
        <button type="submit">确认提交</button>
    </form>
</article>
<footer class="personal_center_footer">
</footer>
<script  type="text/javascript"  src="<?php echo assets(TPLURL . ‘assets/js/jquery-2.1.3.min.js‘) ;?>"></script>
<script  type="text/javascript"  src="<?php echo assets(TPLURL . ‘assets/js/bootstrap.min.js‘) ;?>"></script>
<script  type="text/javascript"  src="<?php echo assets(TPLURL . ‘assets/js/sweetalert.min.js‘) ;?>"></script>
<script  type="text/javascript"  src="<?php echo assets(TPLURL . ‘assets/js/common.js‘) ;?>"></script>
<script  type="text/javascript"  src="<?php echo assets(TPLURL . ‘assets/js/feedback.js‘) ;?>"></script>
</body>
</html>

ajax 提交]

/**
 * public common
 * $ mod_reg 2013-06-07 00:09:13
 * @author Changhe<[email protected]>
 */
$(function(){
    feedback_init();
});
function feedback_init(){
    $(‘#form-feedback‘).submit(function(){
        var senddata={
            explain:$(‘#explain‘).val(),
            pic:$(‘#pic‘).val(),
        };
        if(senddata.explain.length<=10){
            alert("您宝贵的的意见不能少于10个汉字");
            return false;
        }
        //连接到 _mod_mod_feed
        var url=‘/feed/add.html?ajax=json&r=‘+random();
        $.post(url, $(this).serialize(), function(data){
            if(data.error == 0){
                alert(data.message);
            }else{
                swal(data.message);
            }
        });
        return false;
    });
} 

ajax传到—mod/mod_feed.php

切忌:定义了一定要在  index。php下面配置

class mod_feed extends mobileweixin{
/**
 * 意见反馈
 **/
    public function feed_init() {    

    }
    public function action_add() {
        if($_GET[‘ajax‘] == ‘json‘){
            $post = $_POST;
            $data=array(
                ‘explain‘=>trim($_POST[‘explain‘]),
                ‘pic‘=>trim($_POST[‘pic‘]),
                ‘status‘=>FeedbackModel::Notviewed,
                ‘AppID‘=>appid(),
            );
            if(empty($data[‘explain‘])){
                $this->_alert(ERROR, "您宝贵的的意见不能少于10个汉字");
            }
            $FeedbackModel = new FeedbackModel($data);
            $FeedbackModel->save();
        }
    }
}

手机提交完成

后台管理—data/cpapp_nav.php添加目录

在_mod/mod_app.php 定义

    public function action_feedback() {
        import(‘org.mod.feedback‘);
        $app=new feedback($this);
        $method_name=‘on_‘.$this->_CF[‘type‘];
        if(method_exists($app, $method_name)){
            $app->$method_name();
        }else{
            $this->_alert(ERROR, PARAM_ERROR);
        }
    }

里面引入了 system/org/mod/class.feedback.php

<?php
/**
* @用户反馈
* @author qy
* @time 2015-06-05
*/
import ( ‘org.mod.ModPublic‘ );
class feedback extends ModPublic {
    private $tab_feedback;
    // 实例化 引入
    function app_init() {
        $this->tab_feedback = $this->mongodb ()->feedback;
        $this->t->_view [‘extcss‘] = array (
                ‘ext_agent‘
        );
        $this->t->_view [‘extjs‘] = array (
                ‘ext_agent‘
        );
    }
    /**
     * @功能:反馈信息
     * @return void
     * @author qy
     *
     */
    public function on_index() {
        $feedback = FeedbackModel::orderBy("status",1)->orderBy("_id",-1)->get();
        $this->t->_view [‘datalist‘] = $feedback;
    }
    public function on_read() {
        $id = intval($_GET[‘id‘]);
        if(!$id){
            $this->_alert(ERROR, ‘参数错误‘);
        }
        //查找ID下 对应的参数
        $feedback = FeedbackModel::find ($id);
        if (isset ( $_GET[‘id‘] ) && intval ( $_GET[‘id‘] )) {
            $info = FeedbackModel::find($_GET[‘id‘]);
            $info ->status = 1;
            $info->save();
        }
        //显示详情
        $this->t->_view [‘datalist‘] = $feedback;
    }
}
?>
FeedbackModel::这个是自定义了参数特别注意   Notviewed 的引入
class FeedbackModel extends MongoLModel
{
    public $collectionName = "feedback";
    const Notviewed = 0; //0未查看 1已查看
    //自动递增
    public $autoIncrement = true;
    //时间戳
    public $timestamp = true;
}
 
时间: 2024-12-15 00:35:39

php moungoDB的相关文章