国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 語言 > PHP > 正文

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

2024-05-05 00:10:52
字體:
供稿:網(wǎng)友

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

thinkphp3.2 where 條件查詢

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

查詢條件

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

 

含義 TP運(yùn)算符 SQL運(yùn)算符 例子 實(shí)際查詢條件
等于 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á)式查詢,支持SQL語法      

 

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

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

復(fù)查的查詢語句

有的時候,我們希望通過一次的查詢就能解決問題,這個時候查詢條件往往比較復(fù)雜,但是卻比多次查詢庫來的高效。

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

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

1. 區(qū)間查詢(一個值得多種情況)

默認(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ù)合查詢

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

$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ù)需求,靈活使用(無限套下去)

3. sql 查詢

如果有設(shè)置了讀寫分離的話 query 是查詢 execute是更新保存

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

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

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

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

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

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


注:相關(guān)教程知識閱讀請移步到PHP教程頻道。
發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表

圖片精選

主站蜘蛛池模板: 吴旗县| 岳普湖县| 卢氏县| 大名县| 噶尔县| 阳朔县| 灵宝市| 会理县| 彰武县| 秦安县| 台中市| 通化市| 凤翔县| 太康县| 苍溪县| 莫力| 永吉县| 汤原县| 南通市| 河东区| 大新县| 临海市| 宁南县| 民权县| 独山县| 邵阳县| 西平县| 庐江县| 甘谷县| 离岛区| 仁怀市| 凌海市| 商河县| 汝阳县| 遵化市| 仪陇县| 奈曼旗| 宜昌市| 大宁县| 舒兰市| 苍溪县|