您的位置:首页 > 编程语言 > PHP开发

Thinkphp框架基础之使用sql语句

2016-09-07 10:29 302 查看
作为一名使用php语言编程的程序员,Tp框架受到众多人喜欢 ,因为简答容易上手,本人也是比较喜欢用tp框架。现在市面上多用thinkphp3.2 thinkphp5.0版本。

今天就分享一个实用经验,今天我在做搜索的时候,发现框架不太好写查询,所以想用sql语句写like模糊查询

那么重点来了,怎么在Thinphp中执行sql语句了,看看我今天的一段查询代码

    public function index(){

        $data = Db::table("app_addoon")->select();

        //获得type类型,确定显示(0)插件or(1)模板or(2)扩展

        $type = Request::instance()->param("type");

        if($type!=NULL)

        {

          $data = Db::table("app_addoon")->where("type",$type)->select();    

        }

        //添加搜索功能

        $search = Request::instance()->post("search");

        if($search!=NULL)

        {

          $data = Db::table("app_addoon")->query("select * from app_addoon where name like '%$search%' ");

        }

        $this->assign('data',$data);

        return $this->view->fetch('index');

    }
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  like模糊查询 php