最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

thinkphp3.2框架中where條件查詢(xún)用法總結(jié)

 更新時(shí)間:2019年08月13日 10:11:39   作者:小叔哥哥  
這篇文章主要介紹了thinkphp3.2框架中where條件查詢(xún)用法,總結(jié)分析了thinkphp3.2中where條件查詢(xún)中常用的各種查詢(xún)條件、以及各種復(fù)合查詢(xún)實(shí)現(xiàn)方法,需要的朋友可以參考下

本文實(shí)例講述了thinkphp3.2框架中where條件查詢(xún)用法。分享給大家供大家參考,具體如下:

thinkphp3.2 where 條件查詢(xún)

在連貫操作中條件where的操作有時(shí)候自己很暈,所以整理下,有助于使用

查詢(xún)條件

支持的表達(dá)式查詢(xún),tp不區(qū)分大小寫(xiě)

含義 TP運(yùn)算符 SQL運(yùn)算符 例子 實(shí)際查詢(xún)條件
等于 EQ = $where['id'] = array('EQ','1') id = 2
不等于 NEQ != $where['id'] = array('NEQ','1') id!=2
大于 GT > $where['id'] = array('GT','1') id >1
大于等于 EGT EGT $where['id'] = array('EGT','1') id>=1
小于 < < $where['id'] = array('lt',1) id < 1
小于等于 <= <= $where['id'] = array('elt',1) id<=1
匹配 like like where[′id′]=array(′like′,′where[′id′]=array(′like′,′where['id'] = array('like','begin%')
$where['id'] = array('like','%begin%')
where id like '%begin'
where id like 'begin%'
where id like'%begin%
在范圍內(nèi)包括倆端值 between 0<=id<=10 $where['id'] = array('between',array('0','10')) where id between 0 and 10
不在范圍內(nèi) not between 0 >id and 1o < id $where['id'] = array('not between',array('0','10')) where id not between 0 and 10
在枚舉的值中 in in $where['id'] = array('in',array('1','2','5')) where id in ('1','2','3')
不在枚舉值中 not in not in $where['id'] = array('not in',array('1','2',5)) where id not in ('1','2','5')
exp 表達(dá)式查詢(xún),支持SQL語(yǔ)法

exp 是表達(dá)式的意思,如果你覺(jué)得對(duì)于一個(gè)值限制條件太多的話(huà)就可以用這個(gè)

$where['id'] = array('exp','in ( select id from id from tableb)');

復(fù)查的查詢(xún)語(yǔ)句

有的時(shí)候,我們希望通過(guò)一次的查詢(xún)就能解決問(wèn)題,這個(gè)時(shí)候查詢(xún)條件往往比較復(fù)雜,但是卻比多次查詢(xún)庫(kù)來(lái)的高效。

實(shí)在是搞不定的話(huà)就直接用$where['_string'] = 'xxxx', 這個(gè)代表查詢(xún)的時(shí)候拼接上 xxx 條件,一次性解決問(wèn)題

$where['_string'] = 'left join A on A.id = b.id where a.id not in (select id from C)';

1. 區(qū)間查詢(xún)(一個(gè)值得多種情況)

默認(rèn)是 and

$where['id'] =array(array('neq','8'),array('elt','200'),'and'); // 小于等于200 不等于 8
$where['id'] = array(array('neq','8'),'array('neq','10')','or'); // 不等于8或者不等于10

2. 復(fù)合查詢(xún)

相當(dāng)于封裝了新的查詢(xún)條件在里面

$where['a'] = 5;
$where['b'] = 6;
$where['_logic'] = 'or';

sql:where a = 5 or b = 6;

$condition['c'] = '3';
$condition['d'] = '4'
$condition['_logic'] = 'or'
$where['a'] = 9;
$where['_complex'] = $condition;

sql: where a=9 and (c = 3 or d = 4)

根據(jù)需求,靈活使用(無(wú)限套下去)

3. sql 查詢(xún)

如果有設(shè)置了讀寫(xiě)分離的話(huà) query 是查詢(xún) execute是更新保存

M()->query('select * from a');
M()->execute('update a set counts = 3 where id = 1103')

4. 獲取要執(zhí)行的sql 語(yǔ)句

有的時(shí)候條件太復(fù)雜,比如 id in(xxxxx),這個(gè)xxx就是通過(guò)一系列操作獲得的結(jié)果,嫌麻煩的就直接 都扔進(jìn)去,寫(xiě)sql 又長(zhǎng),就直接獲取sql語(yǔ)句扔進(jìn)去

1.fetchsql
2.buildsql
3.select(false)

M('user')->fetchsql(true)->select();
M('user')->buildsql();
M('user')->select(false);

更多關(guān)于thinkPHP相關(guān)內(nèi)容感興趣的讀者可查看本站專(zhuān)題:《ThinkPHP入門(mén)教程》、《thinkPHP模板操作技巧總結(jié)》、《ThinkPHP常用方法總結(jié)》、《codeigniter入門(mén)教程》、《CI(CodeIgniter)框架進(jìn)階教程》、《Zend FrameWork框架入門(mén)教程》及《PHP模板技術(shù)總結(jié)》。

希望本文所述對(duì)大家基于ThinkPHP框架的PHP程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論

沂水县| 马关县| 峨边| 和顺县| 南宁市| 台中县| 邯郸县| 怀宁县| 合山市| 定远县| 商水县| 黎城县| 米易县| 玛多县| 寻乌县| 海南省| 武定县| 焦作市| 江永县| 邵东县| 尼玛县| 喀什市| 澜沧| 都江堰市| 报价| 阿克陶县| 航空| 吉木萨尔县| 开封县| 洛宁县| 遂昌县| 义乌市| 博爱县| 佛学| 英德市| 萝北县| 嘉兴市| 渭南市| 平果县| 牙克石市| 东乡|