当前位置:网站首页>Thinkphp6中where条件中字段与字段比较条件的写法
Thinkphp6中where条件中字段与字段比较条件的写法
2020-11-07 20:56:00 【daydaydream】
今天进行系统测试的时候突然发现原来写好的效果不正常了,仔细排查了所有代码发现如下:
StorePink::where('id',1)->whereColumn('pinkAccount','<','people')->inc('pinkAccount')->update()
这段代码是作用是查找StorePink表中的列pinkAccount是否小于people,但是这段代码打印出来的语句是:
SELECT * FROM
StorePink
WHERE id='1' AND `pinkAccount < people LIMIT 1
ThinkPHP解析出来的时候把原来的字段people解析成了字符串了,所以该语句报错。
解决方法
1 正确的写法如下
大家注意看下两段代码where条件分别是:
where('pinkAccount','>','people') //这里字段与字段之间用 > 隔开,表示>后面的是字段值而非字段
where('pinkAccount',' > people') //这里把 > 与后面的字段写在了一起,即字段与字段之间的比较
2 使用关键词whereColumn(此方法在ThinkPHP6的用户手册中找到)
StorePink::where('id',$order['pink_id'])->whereColumn('pinkAccount','<','people')->inc('pinkAccount')->update()
生成的SQL语句如下:
SELECT * FROM StorePink
WHERE ( pinkAccount
> people
)
版权声明
本文为[daydaydream]所创,转载请带上原文链接,感谢
https://blog.51cto.com/13238147/2547565
边栏推荐
- 技术债务是对业务功能缺乏真正的理解 -daverupert.com
- DOM节点操作
- Let's talk about the locks in the database
- Practice of Xiaoxiong school development board: real equipment access of smart street lamp sandbox experiment
- websocket+probuf.原理篇
- 不懂数据库索引的底层原理?那是因为你心里没点b树
- 【涂鸦物联网足迹】物联网主流通信方式
- 带你深入了解 GitLab CI/CD 原理及流程
- Andque.
- 是时候结束 BERTology了
猜你喜欢
Analysis of kubernetes service types: from concept to practice
华为HCIA笔记
Improvement of maintenance mode of laravel8 update
洞察——风格注意力网络(SANet)在任意风格迁移中的应用
Reflection on a case of bus card being stolen and swiped
awk实现类sql的join操作
The official 1909 version of win10 cannot open the real-time protection solution of virus and threat protection in windows security center.
What should be considered in the promotion plan outside the station?
Big data algorithm - bloon filter
How to learn technology efficiently
随机推荐
小熊派开发板实践:智慧路灯沙箱实验之真实设备接入
【涂鸦物联网足迹】物联网主流通信方式
洞察——风格注意力网络(SANet)在任意风格迁移中的应用
一文详解微服务架构
聊聊Go代码覆盖率技术与最佳实践
高级并发编程系列九(Lock接口分析)
Reflection on a case of bus card being stolen and swiped
There's not much time left for Kwai Chung.
[graffiti footprints of Internet of things] mainstream communication mode of Internet of things
技术总监7年自述——如何选择一家好公司
[漫谈] 软件设计的目标和途径
Git code submission operation, and git push prompt failed to push some refs'xxx '
Code Review Best Practices
建议患者自杀,OpenAI警告:GPT-3用于医疗目的风险太高
Three steps, one pit, five steps and one thunder, how to lead the technical team under the rapid growth?
Huawei HCIA notes
Count the frequency of letters in text (case insensitive)
Summary of the resumption of a 618 promotion project
[C + + learning notes] how about the simple use of the C + + standard library STD:: thread?
Stack bracket matching