您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
webman-查詢構造器-参数分组,whereExists的用法
发布时间:2022-02-05 12:20:19编辑:雪饮阅读()
實例:
public function index(Request $request)
{
ini_set('memory_limit','4096M');
//參數分組
$data = Db::table('ecms_news')
->where('username', '=', '雪饮')
->where(function ($query) {
$query->where('classid', '>', 83)
->orWhere('newspath', '=', '2015-02-03');
})
->get();
$paramsGroup=isset($data[0]) ? $data[0] : [];
//whereExists
$data = Db::table('ecms_news')
->whereExists(function ($query) {
$query->select(Db::raw(1))
->from('ecms_news_data_1')
->whereRaw('phome_ecms_news_data_1.classid = phome_ecms_news.classid');
})
->get();
$whereExists=isset($data[0]) ? $data[0] : [];
$all=compact("paramsGroup","whereExists");
var_dump($all);
return response("ok");
}
構造的sql:
select * from `phome_ecms_news` where `username` = '雪饮' and (`classid` > 83 or `newspath` = '2015-02-03')
select * from `phome_ecms_news` where exists (select 1 from `phome_ecms_news_data_1` where phome_ecms_news_data_1.classid = phome_ecms_news.classid)
這裏的select 1的理解:
有时候为了提高效率,只是为了测试下某个表中是否存在记录,就用1来代替。常搭配 exists方法当条件使用。
實例被請求時:
[root@localhost webman]# /usr/local/php734/bin/php -c /usr/local/php734/lib/php.ini start.php start
Workerman[start.php] start in DEBUG mode
----------------------------------------- WORKERMAN -----------------------------------------
Workerman version:4.0.26 PHP version:7.3.4
------------------------------------------ WORKERS ------------------------------------------
proto user worker listen processes status
tcp root webman http://0.0.0.0:8787 4 [OK]
tcp root monitor none 1 [OK]
---------------------------------------------------------------------------------------------
Press Ctrl+C to stop. Start success.
訪問了全局中間件!
array(2) {
["paramsGroup"]=>
object(stdClass)#54 (37) {
["id"]=>
int(83)
["classid"]=>
int(67)
["ttid"]=>
int(0)
["onclick"]=>
int(4495)
["plnum"]=>
int(0)
["totaldown"]=>
int(0)
["newspath"]=>
string(10) "2015-02-03"
["filename"]=>
string(2) "83"
["userid"]=>
int(1)
["username"]=>
string(6) "雪饮"
["firsttitle"]=>
int(0)
["isgood"]=>
int(0)
["ispic"]=>
int(1)
["istop"]=>
int(0)
["isqf"]=>
int(0)
["ismember"]=>
int(0)
["isurl"]=>
int(0)
["truetime"]=>
int(1422962195)
["lastdotime"]=>
int(1423559710)
["havehtml"]=>
int(1)
["groupid"]=>
int(0)
["userfen"]=>
int(0)
["titlefont"]=>
string(0) ""
["titleurl"]=>
string(48) "/mobanfenxiang/gerenbokemoban/2015-02-03/83.html"
["stb"]=>
int(1)
["fstb"]=>
int(1)
["restb"]=>
int(1)
["keyboard"]=>
string(75) "测试文章关键字1,测试文章关键字2,测试文章关键字3,雪饮"
["title"]=>
string(42) "情侣博客模板系列之《回忆》PSD"
["newstime"]=>
int(1422962138)
["titlepic"]=>
string(84) "/d/file/mobanfenxiang/gerenbokemoban/2015-02-09/66a6753961114f06ae33e3fed8eeca93.jpg"
["ftitle"]=>
string(0) ""
["smalltext"]=>
string(247) " 情侣博客模板系列之《回忆》,分为四个主要部分,照片墙、情侣介绍、图文组、祝福模块。适合爱晒照片的小情侣,或者喜欢旅行类的朋友们,希望喜欢这款模板。效果上,css3动画会"
["diggtop"]=>
int(0)
["push_weixin_material"]=>
int(0)
["push_baidu_last_time"]=>
int(0)
["push_weixin_material_last_time"]=>
int(0)
}
["whereExists"]=>
object(stdClass)#125 (37) {
["id"]=>
int(114)
["classid"]=>
int(83)
["ttid"]=>
int(0)
["onclick"]=>
int(62)
["plnum"]=>
int(0)
["totaldown"]=>
int(0)
["newspath"]=>
string(0) ""
["filename"]=>
string(3) "114"
["userid"]=>
int(1)
["username"]=>
string(6) "雪饮"
["firsttitle"]=>
int(0)
["isgood"]=>
int(0)
["ispic"]=>
int(1)
["istop"]=>
int(0)
["isqf"]=>
int(0)
["ismember"]=>
int(0)
["isurl"]=>
int(0)
["truetime"]=>
int(1423920308)
["lastdotime"]=>
int(1425445123)
["havehtml"]=>
int(1)
["groupid"]=>
int(0)
["userfen"]=>
int(0)
["titlefont"]=>
string(0) ""
["titleurl"]=>
string(30) "/manshenghuo/xinshang/114.html"
["stb"]=>
int(1)
["fstb"]=>
int(1)
["restb"]=>
int(1)
["keyboard"]=>
string(0) ""
["title"]=>
string(30) "一个程序员的爱情故事"
["newstime"]=>
int(1423920134)
["titlepic"]=>
string(76) "/d/file/manshenghuo/xinshang/2015-02-14/01e4753ff30b6bf0838b6e55cbe88c39.jpg"
["ftitle"]=>
string(35) "程序员,爱情,雪饮个人博客"
["smalltext"]=>
string(170) " //一个程序员的爱情故事 public class MyLoveStory { public static void Main(string[] args) { //The ForeStory int result"
["diggtop"]=>
int(0)
["push_weixin_material"]=>
int(0)
["push_baidu_last_time"]=>
int(0)
["push_weixin_material_last_time"]=>
int(0)
}
}
关键字词:webman,查詢構造器,参数分组,whereExists
相关文章
- webman-查詢構造器-orWhereColumn 的用法
- webman-查詢構造器-whereColumn 的用法
- webman-查詢構造器-whereDate,whereMonth,whereDay,wh
- webman-查詢構造器-whereNull ,whereNotNull,orWhereN
- webman-查詢構造器-whereIn、whereNotIn、orWhereIn
- webman-查詢構造器-whereBetween 與 orWhereBetween
- webman-查詢構造器-閉包查詢、whereBetween 與 orWher
- webman-查詢構造器-條件數組、where與orWhere
- webman-查詢構造器-where語句-等於、大於等於、不等於
- webman-查詢構造器-Union 语句-合并結果集