您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
webman-查詢構造器-閉包查詢、whereBetween 與 orWhereBetween
发布时间:2022-02-04 22:39:21编辑:雪饮阅读()
webman可以传一个闭包给 orWhere 方法作为第一个参数。
whereBetween / orWhereBetween 方法验证字段值是否在给定的两个值之间。
控制器實例:
public function index(Request $request)
{
ini_set('memory_limit','4096M');
//閉包查詢,下面實例相當於:
// SQL: select * from ecms_news where id > 100 or (username = '雪饮' and id > 50)
$ClosureQuery= Db::table('ecms_news')
->where('id', '>', 100)
->orWhere(function($query) {
$query->where('username', '雪饮')
->where('id', '>', 50);
})
->get();
$ClosureQuery0=$ClosureQuery[0];
//whereBetween / orWhereBetween 方法验证字段值是否在给定的两个值之间:
$where_Between = Db::table('ecms_news')
->whereBetween('id', [1, 100])
->get();
$whereBetween0=$where_Between[0];
$orWhere_Between = Db::table('ecms_news')
->orWhereBetween('id', [1, 100])
->get();
$orWhere_Between0=$orWhere_Between[0];
$all=compact("ClosureQuery0","whereBetween0","orWhere_Between0");
var_dump($all);
return response("ok");
}
實例被訪問:
[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(3) {
["ClosureQuery0"]=>
object(stdClass)#54 (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)
}
["whereBetween0"]=>
object(stdClass)#44 (37) {
["id"]=>
int(82)
["classid"]=>
int(67)
["ttid"]=>
int(0)
["onclick"]=>
int(4193)
["plnum"]=>
int(0)
["totaldown"]=>
int(0)
["newspath"]=>
string(10) "2015-02-02"
["filename"]=>
string(2) "82"
["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(1422881003)
["lastdotime"]=>
int(1423533759)
["havehtml"]=>
int(1)
["groupid"]=>
int(0)
["userfen"]=>
int(0)
["titlefont"]=>
string(0) ""
["titleurl"]=>
string(48) "/mobanfenxiang/gerenbokemoban/2015-02-02/82.html"
["stb"]=>
int(1)
["fstb"]=>
int(1)
["restb"]=>
int(1)
["keyboard"]=>
string(45) "情侣博客,博客模板,情侣模板,雪饮"
["title"]=>
string(43) "情侣博客模板系列之《回忆》Html"
["newstime"]=>
int(1422880895)
["titlepic"]=>
string(84) "/d/file/mobanfenxiang/gerenbokemoban/2015-02-09/f3705b766cd096483303db014b2cb929.jpg"
["ftitle"]=>
string(0) ""
["smalltext"]=>
string(245) " Html5+css3情侣博客模板,主题《回忆》,使用css3技术实现网站动画效果,主题《回忆》,分为四个主要部分,照片墙、情侣介绍、图文组、祝福模块。适合爱晒照片的小情侣,或者喜欢"
["diggtop"]=>
int(0)
["push_weixin_material"]=>
int(0)
["push_baidu_last_time"]=>
int(0)
["push_weixin_material_last_time"]=>
int(0)
}
["orWhere_Between0"]=>
object(stdClass)#2658 (37) {
["id"]=>
int(82)
["classid"]=>
int(67)
["ttid"]=>
int(0)
["onclick"]=>
int(4193)
["plnum"]=>
int(0)
["totaldown"]=>
int(0)
["newspath"]=>
string(10) "2015-02-02"
["filename"]=>
string(2) "82"
["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(1422881003)
["lastdotime"]=>
int(1423533759)
["havehtml"]=>
int(1)
["groupid"]=>
int(0)
["userfen"]=>
int(0)
["titlefont"]=>
string(0) ""
["titleurl"]=>
string(48) "/mobanfenxiang/gerenbokemoban/2015-02-02/82.html"
["stb"]=>
int(1)
["fstb"]=>
int(1)
["restb"]=>
int(1)
["keyboard"]=>
string(45) "情侣博客,博客模板,情侣模板,雪饮"
["title"]=>
string(43) "情侣博客模板系列之《回忆》Html"
["newstime"]=>
int(1422880895)
["titlepic"]=>
string(84) "/d/file/mobanfenxiang/gerenbokemoban/2015-02-09/f3705b766cd096483303db014b2cb929.jpg"
["ftitle"]=>
string(0) ""
["smalltext"]=>
string(245) " Html5+css3情侣博客模板,主题《回忆》,使用css3技术实现网站动画效果,主题《回忆》,分为四个主要部分,照片墙、情侣介绍、图文组、祝福模块。适合爱晒照片的小情侣,或者喜欢"
["diggtop"]=>
int(0)
["push_weixin_material"]=>
int(0)
["push_baidu_last_time"]=>
int(0)
["push_weixin_material_last_time"]=>
int(0)
}
}
关键字词:webman,查詢構造器,閉包查詢,whereBetween 與 orWhereBetween