针对tp6model查询失效给出范例

   /**
     * author:leishaofa
     * date:20190916
     * effect:查询指定条件的单条文章
     *
     */
    public function getwhereone($where){
        try{
            $result=$this->where($where)->find();
        }catch (\Exception $e){
            Log::error(htmlspecialchars($e));
            return ['code'=>4001,'msg'=>"系统文章查询出错",'data'=>json_encode([])];
        }
        var_dump($result);
        $sql=$this->getLastSql();
        var_dump($sql);
        if(!$result){

            $result=Db::table($this->table)->query($sql);
            $result=$result[0];
            print_r("tp6自带查询失效进入原生查询");
        }
        print_r($result?"aaaaaaaaa":"bbbbbbbbbbbbbb");
        if($result){
            $result=is_array($result)?$result:$result->toArray();
            $resultdata=array(
                'titlle'=>htmlspecialchars_decode($result['title']),
                'id'=>$result['article_id'],
                'cat_id'=>$result['cat_id'],
                'time'=>$result['keywords'],
                'endtime'=>$result['keywords'] == 23?0:$result['keywords']+1,
                'description'=>htmlspecialchars_decode($result['description']),
                'content'=>htmlspecialchars_decode($result['content'])
            );
            return ['code'=>1,'msg'=>"成功",'data'=>$resultdata];
        }else{
            return ['code'=>4001,'msg'=>"未找到",'data'=>json_encode([])];
        }
    }

这个是model里面的一个方法,查询的一张文章表,虽然这样可能丢失性能,但是不知道那些位置调用了,所以暂且都做的这种兼容处理,等有时间,写一个,tp查询方法组装成sql,就可以全部替换成原生得了

你可能感兴趣的:(php)