精华内容
下载资源
问答
  • 2021-04-29 08:07:25

    laravel中的 DB::raw() 和DB::RAW()是同一种功能;用法如下$real = 66;

    $res = Data::where('id','152878863117610072368534')

    ->update([ 'time_len'=>DB::raw("time_len + ".$real), ]);

    $res = Data::where('id','152878863117610072368534')

    ->update(['time_len'=>DB::raw("time_len + 6"), ]);

    可以查出当年表中当前条件的字段的值 并可以在里面做加减乘除等运算

    laravel whereRaw 和 where(DB::raw(''))

    用 where(DB::raw(''))的时候,结尾会被增加一个莫名其妙的 is null()

    用toSql()发现的,而使用whereRaw则不会

    $student=DB::table("vipinfo")->whereRaw('vip_ID> ? and vip_fenshu >= ?',[2,300])->get();//多个条件

    使用laravel框架中的DB查询mysql数据库的时候,综合遇到执行mysql函数或者,自定义字段,一般情况下DB会把传入的函数当做字段处理

    方法如下:

    DB:raw('函数或者字段');

    DB:whereRaw('函数或者字段');

    DB:orderbyRaw('函数或者字段');

    例子:DB::raw('rand()')、DB::raw('date()')

    更多相关内容
  • } $chanpinmaidian_arr = ArticleModel::whereRaw("art_type=1 and status=2 and is_enabled=1 and is_delete=0 and ($chanpinmaidian_map)") ->field('id,title,nick_name,art_type,video_url,video_other_url,zan...

    public function video_list_order(){
            try{
                //处理搜索条件
                $map = [];
                //分类:0文章;1视频;2直播
                $map[] = ['art_type','=',"1"];
                //是否删除:0否;1是
                $map[] = ['is_delete','=',"0"];
                //标题搜索
                $title = Request::param('title','');
                if($title != ''){
                    $map[] = ['title','like',"%{$title}%"];
                }
                //分类搜索
                $class_id = Request::param('class_id','');
                if($class_id != ''){
                    $map[] = ['class_id','=',"$class_id"];
                }
                //审核状态(0:待提交;1:待审核;2:审核通过;3:审核拒绝)
                $status = Request::param('status','');
                if($status !== ''){
                    $map[] = ['status','=',"$status"];
                }
                //是否启用:0禁用;1启用
                $is_enabled = Request::param('is_enabled','');
                if($is_enabled !== ''){
                    $map[] = ['is_enabled','=',"$is_enabled"];
                }
                //发布者
                $nick_name = Request::param('nick_name','');
                if($nick_name != ''){
                    $map[] = ['nick_name','like',"%$nick_name%"];
                }

                //视频标签
                $article_label_name = Request::param('article_label_name','');
                if($article_label_name != ''){
                    $map[] = ['article_label_name','like',"%$article_label_name%"];
                }

                $list = Db::table('rui_article')->where($map)
                    ->fieldRaw("(CASE
                        WHEN all_num=0 THEN TRUNCATE(0,0)
                        ELSE TRUNCATE(wan_num/all_num*100,0) END) as CompletionRate,id,title,art_type,cover_type,cover_images,label_id,
                    label_name,article_label_id,article_label_name,status,uid,nick_name,avatar,status,class_id,class_name,
                    zan_num,virtual_views_num,view_num,collect_num,comment_num,share_num,
                    is_rec,is_top,is_enabled,is_delete,create_time,update_time,video_url,video_other_url,
                    wan_num as FinishBroadcasting,wei_num as UnfinishedBroadcasting,all_num as Broadcasting")
                    ->order('CompletionRate','desc')
                    ->order('id','desc')
                    ->page(Request::param('page'))->limit(Request::param('limit'))
                    ->select()->toArray();
                foreach ($list as $k=>$v){
                    $list[$k]['is_rec_bool'] = $v['is_rec'] == 1 ? true :false;
                    $list[$k]['is_top_bool'] = $v['is_top'] == 1 ? true :false;
                    $list[$k]['is_enabled_bool'] = $v['is_enabled'] == 1 ? true :false;
                    $list[$k]['is_delete_bool'] = $v['is_delete'] == 1 ? true :false;
                    if(!$v['video_url']){
                        $list[$k]['video_url'] = $v['video_other_url'];
                    }
                    $list[$k]['CompletionRate'] = "{$v['CompletionRate']}%";
                }
                $arr['list'] = $list;
                $arr['count'] = Db::table('rui_article')
                    ->where($map)->count();
            }catch (ValidateException $e) {
                // 验证失败 输出错误信息
                throw new ParameterException(['msg'=>$e->getError()]);
            }
            return $arr;
        }

    $chanpinmaidian_arr = ArticleModel::whereRaw("art_type=1 and status=2 and is_enabled=1 and is_delete=0 and ($chanpinmaidian_map)")
                        ->field('id,title,nick_name,art_type,video_url,video_other_url,zan_num,comment_num,share_num,is_coin_fuli')
                        ->order('id','desc')
                        ->page($page_rand)->limit(1)
                        ->select()->toArray();

    展开全文
  • 条件复杂组合查询 (whereRaw

    千次阅读 2021-04-26 14:27:01
    解决方式:whereRaw,结果: 成功 $time = time(); $whereOrRaw = "(send_time $time} AND user_type = 20 AND `json` LIKE '%{$no}%') or (send_time $time} AND user_type = 10)"; $list = Db::name('notice')->...

    想满足的sql:

    SELECT
    	* 
    FROM
    	`p_notice` 
    WHERE
    	( ( send_time <  (当前时间) AND user_type = 20 AND `json` LIKE '%123456%' ) OR ( send_time < (当前时间)AND user_type = 10 ) ) 
    ORDER BY
    	`send_time` DESC
    

    所在框架:thinkphp6
    解决方式:_logic 和 _complex,结果 : 失败

     $time = time();
     $where_1['user_type'] = ['eq',10];
     $where_1['send_time'] =  ['lt', "$time"];
     $where_1['_logic'] =  'or';
     $map['_complex1']= $where_1;
     
     $where_2['user_type'] =  ['eq', 20];
     $where_2['send_time'] = ['lt', "$time"];
     $where_2['user_json'] = ['like', "%$no%"];
     $map['_complex2'] = $where_2;
     $list = Db::name('notice')->where($map)->select();
    

    解决方式:whereRaw,结果: 成功

     $time = time();
     $whereOrRaw = "(send_time < {$time} AND user_type = 20 AND `json` LIKE '%{$no}%') or (send_time < {$time} AND user_type = 10)";
     $list = Db::name('notice')->whereOrRaw($whereOrRaw)->paginate(10)->toArray();
    
    展开全文
  • tp5.1查询whereRaw 和 query使用

    千次阅读 2019-10-21 17:57:54
    whereRaw ( 'msg_status = 2 AND status <> 2' . $where . '' , $value ) - > limit ( $limit_start , $limit_length ) - > order ( 'date' , 'desc' ) - > select ( ) ; $total = Db : : name...

    whereRwa

      $where = '';
            $value = [];
    
            if ($senduid) {
                if ($senduid == '全部用户') {
                    $u_id = 0;
                } else {
                    $u_id = DB::name('Member')->where('nickname', $senduid)->value('id');
                }
                $where .= ' AND senduid = :senduid';
                $value['senduid'] = $u_id;
            }
    
            if (!empty($m_status) && $m_status != 'none') {
                $where .= ' AND status = :status';
                $value['status'] = $m_status;
            }
    
            //得到limit参数
            $limit_start = $data['start'];
            $limit_length = $data['length'];
    
            $list = Db::name('messages')->whereRaw('msg_status = 2 AND status <> 2' . $where . '', $value)->limit($limit_start, $limit_length)->order('date', 'desc')->select();
    
            $total = Db::name('messages')->whereRaw('msg_status = 2 AND status <> 2' . $where . '', $value)->count();
    

    query

    //获取一个本周7天以内的资金走向表
    
    
     public function sevenpicture(Request $request)
        {
    
    
            $uid = input('uid');
            //佣金走势图
            $timestr = time();    //当前时间戳
            $now_day = date('w',$timestr);  //当前是周几
    
            //获取周一
            $monday_str = $timestr - ($now_day-1)*60*60*24;
            $monday = date('Y-m-d', $monday_str);
    
            //获取周日
            $sunday_str = $timestr + (7-$now_day)*60*60*24;
            $sunday = date('Y-m-d', $sunday_str);
            for($i=0;$i<7;$i++)
            {
                $arr[date('Y-m-d',strtotime($monday.'+'.$i.'day'))]=0;
            }
    
            $sql =
                "SELECT
            sum(`carprice`) as price,
            date_format(`createtime`,\"%Y-%m-%d\") as date 
        FROM
            `y_agent` 
        WHERE
            `caruid` = :uid
            AND date_format(`createtime`,\"%Y-%m-%d\") BETWEEN :s_time 
            AND :c_time 
        GROUP BY date";
    
    
            $re = Db::query($sql,['uid'=>$uid,'s_time'=>$monday,'c_time'=>$sunday]);
            foreach ($re as $k=>$v)
            {
                $dateinfo[$v['date']] =$v['price'];
            }
    
    
            $linepicture =array_merge($arr,$dateinfo);
    
            foreach ($linepicture as $key=>$value )
            {
                $line[] =[
                    'time'=>$key,
                    'tem'=>$value,
                ];
            }
            //`````````````````````
            if($line)
            {
                return json(['code'=>1,'data'=>$line,'msg'=>"获取数据成功"]);
            }else{
                return json(['code'=>2,'data'=>'','msg'=>"获取数据失败!"]);
            }
    
        }
    
    展开全文
  • laravel中使用whereRaw需要注意sql注入,需要使用占位符?来解决该问题 $query->whereRaw("(concat(IFNULL(`title`,'')) like ?)", ['%test%']);
  • <pre><code> $conversations = Inquiries::whereRaw("( `course` = $request->input('course')) AND( `mobile` = $request->input('mobile') OR 'nic', 'LIKE', '%'.$request->input('nic').'%')") ->...
  • 例子:查询endtime字段时间结束后30分钟的数据 表中值是:endtime =2019-11-22 11:00:00; ->whereTime('endtime', '>=', time()) 但是因为延迟30分钟,上面查询条件的数据就不对,查不到延迟...whereRaw(...
  • laravel whereRaw 和 where(DB::raw('')) 看标题就知道,明显whereRaw似乎是专业和靠谱一些 用where(DB::raw(''))的时候,结尾会被增加一个莫名其妙的 is null() 用toSql()发现的。 $student=DB::table("vipinfo")-&...
  • <p>How can I pass parameters to a method in my query using whereRaw? <p>I've got 'syntax error, unexpected '.'' when trying to add 'latitude' and 'longitude' which are column names: <pre><code>...
  • laravel whereRaw 和 where(DB::raw(''))

    万次阅读 2015-11-26 17:55:17
    laravel whereRaw 和 where(DB::raw('')) 看标题就知道,明显whereRaw似乎是专业和靠谱一些 用 where(DB::raw(''))的时候,结尾会被增加一个莫名其妙的 is null() 用toSql()发现的。
  • <p>Inside the foreach loop I have tried <code>Individualprofile::whereRaw(..)</code> but still the same problem. <p>Below is my full route implementation. <pre><code>Route::get('/get-...
  • $products = Product::whereRaw( 'MATCH(product_name,product_desc,product_category) AGAINST(? IN BOOLEAN MODE)', array($query) )->paginate(5); return View::make('searchResults', array('products'...
  • 今天小编就为大家分享一篇Laravel使用模型实现like模糊查询的例子,具有很好的参考价值,希望对大家有所帮助。一起跟随小编过来看看吧
  • laravel知识总结

    2021-10-14 10:52:20
    whereRaw / orWhereRaw 可以使用 whereRaw 和 orWhereRaw 方法将原生的 where 注入到你的查询中。这些方法接受一个可选的绑定数组作为他们的第二个参数: $orders = DB::table(‘orders’) ->whereRaw(‘price > IF...
  • 可以使用 whereRaw 和 orWhereRaw 方法将原生的 where 语句注入到查询中。这些方法接受一个可选的绑定数组作为他们的第二个参数: $orders = DB::table('orders') ->whereRaw('price > IF(state = "TX", ?, 100)'...
  • ThinkPHP 6 数据库查询,where 、or、and

    千次阅读 2021-06-07 14:23:31
    sql:SELECT * FROM `un2co_user_card` WHERE `birthday` = 'not null' 字符串条件: 直接使用字符串条件直接查询和操作 Db::table('think_user')->whereRaw('type=1 AND status=1')->select(); Thinkphp6 的 where ...
  • ->from('orders') ->whereRaw('orders.user_id = users.id'); }) ->get(); 上述代码与下列sql等价 select * from users where exists ( select 1 from orders where orders.user_id = users.id ) JSON类型的列查询 ...
  • ThinkPHP6 where()

    2021-07-17 11:11:01
    // whereRaw() 自定义SQL // $user = Db::name('user') // ->whereRaw('(username LIKE "%小%" AND status=1) OR id>0') // ->select(); // 预处理 参数绑定 // $user = Db::name('user') // ->...
  • } else { $sql->whereRaw("match(name, description) against(? IN NATURAL LANGUAGE MODE)", $keyword); } } 参考 ...
  • 关于FIND_IN_SET

    2022-01-10 13:12:37
    select * from `tbname` where !FIND_IN_SET(1,2,3 columnName) 翻译: $string=1,2,3; Goods::query()->whereRaw('!FIND_IN_SET(?,columnName)', $string)
  • Laravel find in set排序

    2019-05-17 10:58:00
    $query->whereRaw("DATE_FORMAT(FROM_DAYS(TO_DAYS(NOW())-TO_DAYS(birthday)), '%Y')+0 between $ageType[0] and $ageType[1]"); } }) ->where(function ($query) use ($timeType) { //1本周,2下周 if ($...
  • }) ->where(function ($where) { $where->WhereRaw(sprintf( '( (mission.type = %d and ((user_mission_log.create_time >= "%s" and user_mission_log.create_time ) or (user_mission_log.create_time is null) ...
  • ThinkPHP6,查询语句的where的完美用法

    千次阅读 2021-07-28 11:38:02
    字符串条件 使用字符串条件直接查询和操作,例如: Db::table('think_user')->whereRaw('type=1 AND status=1')->select(); 最后生成的SQL语句是 SELECT * FROM think_user WHERE type=1 AND status=1 使用字符串...
  • $exist = $this ->whereRaw($where) ->find(); 方法2 使用闭包查询 $exist = $this ->where('id','<>',1) ->where(function ($query) use($map1, $map2, $map3) { $query->whereOr([$map1, $map2, $map3]); }) ->...
  • I am using Laravel 4 and have set up the following query:if(Input::get('keyword')) {$keyword = Input::get('keyword');$search = DB::connection()->getPdo()->quote($keyword);...whereRaw("MA...
  • whereRaw('search_price != rrp_price'); $products = $query->get(); </code></pre> <p>So, if i take out the 'search_price < rrp_price' where i get all products filtered by those product ids with ...
  • 这是我当前的迁移:class News extends Migration { public function up() { Schema::create('News', function (Blueprint $table) {... ->whereRaw("MATCH(title,description) AGAINST(? IN BOOLEAN MODE)", array($q))

空空如也

空空如也

1 2 3 4 5 ... 20
收藏数 851
精华内容 340
关键字:

whereRaw