作为一名使用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');
}