当前位置:网站首页>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
边栏推荐
- Insight -- the application of sanet in arbitrary style transfer
- 洞察——风格注意力网络(SANet)在任意风格迁移中的应用
- graph generation model
- Classroom exercises
- Count the frequency of letters in text (case insensitive)
- After pulling four message queues into a group, they quarreled
- Get started, GIT
- Don't treat exceptions as business logic, which you can't afford
- 如何应对事关业务生死的数据泄露和删改?
- The samesite problem of cross domain cookie of Chrome browser results in abnormal access to iframe embedded pages
猜你喜欢
一文详解微服务架构
MongoDB下,启动服务时,出现“服务没有响应控制功能”解决方法
Deep into web workers (1)
The JS solution cannot be executed after Ajax loads HTML
某618大促项目的复盘总结
构造请求日志分析系统
In simple terms, the large front-end framework angular6 practical course (angular6 node.js 、keystonejs、
C language I blog assignment 03
vscode 配置
Annual salary of 900000 programmers is not as good as 3800 civil servants a month? How to choose between stability and high income?
随机推荐
websocket+probuf.原理篇
Ac86u KX Online
不要把异常当做业务逻辑,这性能可能你无法承受
Web API系列(三)统一异常处理
Do not understand the underlying principle of database index? That's because you don't have a B tree in your heart
Don't treat exceptions as business logic, which you can't afford
如何应对事关业务生死的数据泄露和删改?
Share several vs Code plug-ins I use everyday
Exception calling 'downloadstring' with '1' arguments: 'operation timed out'
【原创】ARM平台内存和cache对xenomai实时性的影响
graph generation model
Code Review最佳实践
The CPU does this without the memory
HandlerMethodArgumentResolver使用和原理
我是如何失去团队掌控的?
ajax 载入html后不能执行其中的js解决方法
How to learn technology efficiently
在pandas中使用pipe()提升代码可读性
C language I blog assignment 03
The samesite problem of cross domain cookie of Chrome browser results in abnormal access to iframe embedded pages