当前位置:网站首页>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
边栏推荐
- If you want to forget the WiFi network you used to connect to your Mac, try this!
- Let's talk about the locks in the database
- 「混合云」会是云计算的下一个战场吗?
- Let you have a deep understanding of gitlab CI / CD principle and process
- 一次公交卡被“盜刷”事件帶來的思考
- Facebook开源框架如何简化 PyTorch 实验
- From technology to management, the technology of system optimization is applied to enterprise management
- 带你深入了解 GitLab CI/CD 原理及流程
- A detailed explanation of microservice architecture
- 洞察——风格注意力网络(SANet)在任意风格迁移中的应用
猜你喜欢
三步一坑五步一雷,高速成长下的技术团队怎么带?
洞察——风格注意力网络(SANet)在任意风格迁移中的应用
一次公交卡被“盗刷”事件带来的思考
Business facade and business rule
Do not understand the underlying principle of database index? That's because you don't have a B tree in your heart
Principles of websocket + probuf
Insight -- the application of sanet in arbitrary style transfer
全网最硬核讲解计算机启动流程
浅谈HiZ-buffer
不懂数据库索引的底层原理?那是因为你心里没点b树
随机推荐
go wire 依赖注入入门
一次公交卡被“盜刷”事件帶來的思考
Don't treat exceptions as business logic, which you can't afford
What should be considered in the promotion plan outside the station?
websocket+probuf.原理篇
Exception calling 'downloadstring' with '1' arguments: 'operation timed out'
ajax 载入html后不能执行其中的js解决方法
Code Review Best Practices
站外推广的计划需要考虑哪些呢?
如何高效的学习技术
C language I blog assignment 03
In simple terms, the large front-end framework angular6 practical course (angular6 node.js 、keystonejs、
快速上手Git
How Facebook open source framework simplifies pytorch experiment
C language I blog assignment 03
【涂鸦物联网足迹】物联网主流通信方式
Principles of websocket + probuf
Web API series (3) unified exception handling
Let you have a deep understanding of gitlab CI / CD principle and process
不懂数据库索引的底层原理?那是因为你心里没点b树