当前位置:网站首页>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
StorePinkWHERE 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
边栏推荐
- use Xunit.DependencyInjection Transformation test project
- [graffiti footprints of Internet of things] mainstream communication mode of Internet of things
- Let you have a deep understanding of gitlab CI / CD principle and process
- Kubernetes服务类型浅析:从概念到实践
- On hiz buffer
- MongoDB下,启动服务时,出现“服务没有响应控制功能”解决方法
- PHP安全:变量的前世今生
- static+代码块+多态+异常
- 不要把异常当做业务逻辑,这性能可能你无法承受
- If you want to forget the WiFi network you used to connect to your Mac, try this!
猜你喜欢

Awk implements SQL like join operation

Tips for Mac novices

Code Review Best Practices

统计文本中字母的频次(不区分大小写)

盘点那些争议最大的编程观点,你是什么看法呢?

Using pipe() to improve code readability in pandas

C language I blog assignment 03

深入web workers (上)

Three steps, one pit, five steps and one thunder, how to lead the technical team under the rapid growth?

C语言Ⅰ博客作业03
随机推荐
Awk implements SQL like join operation
laravel8更新之维护模式改进
建议患者自杀,OpenAI警告:GPT-3用于医疗目的风险太高
Kubernetes服务类型浅析:从概念到实践
带你深入了解 GitLab CI/CD 原理及流程
使用 Xunit.DependencyInjection 改造测试项目
【原创】ARM平台内存和cache对xenomai实时性的影响
「混合云」会是云计算的下一个战场吗?
The most hard core of the whole network explains the computer startup process
Let you have a deep understanding of gitlab CI / CD principle and process
DOM节点操作
Using thread communication to solve the problem of cache penetrating database avalanche
从技术谈到管理,把系统优化的技术用到企业管理
laravel8更新之维护模式改进
盘点那些争议最大的编程观点,你是什么看法呢?
Classroom exercises
Three steps, one pit, five steps and one thunder, how to lead the technical team under the rapid growth?
websocket+probuf.原理篇
How to think in the way of computer
留给快手的时间不多了