2016-05-11 14:37:04 3472次浏览 2条回答 1 悬赏 10 金钱

$data = Chat::find()->where(['>', 'id', 45],'uid'=>1])->asArray()->all(); 要怎么改呢?

最佳答案

  • dmodai 发布于 2016-05-12 10:25 举报

    还是预处理的更好用

    Chat::find()->where('id > :id and uid = :uid', [':id'=>118, 'uid'=> 1])->asArray()->all();
    

    如果先看到底运行的原生sql是什么可以用这样

    $query = Post::find()->where('author_id = :author_id and status = :status', [':author_id'=>2, ':status'=> 2]);
          $commandQuery = clone $query;
          echo $commandQuery->createCommand()->getRawSql();
    
          print_r($query->all());
    
    2 条回复
    回复于 2016-05-12 15:13 回复

    谢谢。。再问个问题 select max(id) as id from ht_chat; select后面的查询字段 应该怎么加 用Chat::find()这个。。

    回复于 2016-05-13 11:27 回复

    $query = Post::find()->select('max(id) as max_id ')->where('author_id = :author_id and status = :status', [':author_id'=>1, ':status'=> 2]);
    

    看文档的查询构建器

  • 回答于 2016-05-11 15:45 举报
     Chat::find()->where(['>', 'id', 45])->andWhere(['uid' => 1])->asArray()->all();
    
    3 条回复
    回复于 2016-05-12 15:12 回复

    谢谢。。再问个问题select max(id) as id from ht_chat;select后面的查询字段 应该怎么加 用Chat::find()这个。。

    回复于 2016-05-12 15:12 回复

    谢谢。。再问个问题 select max(id) as id from ht_chat; select后面的查询字段 应该怎么加 用Chat::find()这个。。

    回复于 2016-05-12 15:31 回复
    Chat::find()->where(['>', 'id', 45])->andWhere(['uid' => 1])->max('id');
    
您需要登录后才可以回答。登录 | 立即注册
我的丶关键词
助理

我的丶关键词

注册时间:2016-04-25
最后登录:2017-05-09
在线时长:11小时40分
  • 粉丝1
  • 金钱83
  • 威望0
  • 积分193

热门问题