当前位置:网站首页>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
边栏推荐
- MongoDB下,启动服务时,出现“服务没有响应控制功能”解决方法
- Opencv computer vision learning (10) -- image transform (Fourier transform, high pass filter, low pass filter)
- [original] the influence of arm platform memory and cache on the real-time performance of xenomai
- Count the frequency of letters in text (case insensitive)
- 动态规划——用二进制表示集合的状态压缩DP
- Analysis of the original code of [QT] qthread
- Win10官方1909版本无法打开windows安全中心中病毒和威胁防护的实时保护解决方案。
- 站外推广的计划需要考虑哪些呢?
- [C + + learning notes] how about the simple use of the C + + standard library STD:: thread?
- Huawei HCIA notes
猜你喜欢
如何高效的学习技术
What should be considered in the promotion plan outside the station?
利用线程通信、解决缓存穿透数据库雪崩
C语言I博客作业03
Reflection on a case of bus card being stolen and swiped
Application and principle of handlermethodargumentresolver
Let's talk about the locks in the database
统计文本中字母的频次(不区分大小写)
Advanced concurrent programming series 9 (lock interface analysis)
聊聊Go代码覆盖率技术与最佳实践
随机推荐
工作1-3年的程序员,应该具备怎么样的技术能力?该如何提升?
编程界大佬教你:一行Python代码能做出哪些神奇的事情?
使用“1”个参数调用“DownloadString”时发生异常:“操作超时”
Stack bracket matching
Kylin on kubernetes' practice on eBay
C language I blog assignment 03
【原创】ARM平台内存和cache对xenomai实时性的影响
【涂鸦物联网足迹】物联网主流通信方式
使用 Xunit.DependencyInjection 改造测试项目
Huawei HCIA notes
深入web workers (上)
Reflection on a case of bus card being stolen and swiped
一次公交卡被“盗刷”事件带来的思考
凯撒密码实现
What magic things can a line of Python code do?
不要把异常当做业务逻辑,这性能可能你无法承受
留给快手的时间不多了
带你深入了解 GitLab CI/CD 原理及流程
Technical debt is a lack of real understanding of business functions- daverupert.com
What kind of technical ability should a programmer who has worked for 1-3 years? How to improve?