当前位置:网站首页>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
边栏推荐
猜你喜欢
Git代码提交操作,以及git push提示failed to push some refs'XXX'
Exception calling 'downloadstring' with '1' arguments: 'operation timed out'
C语言I博客作业03
【原创】ARM平台内存和cache对xenomai实时性的影响
ajax 载入html后不能执行其中的js解决方法
Deep into web workers (1)
Code Review最佳实践
想要忘记以前连接到Mac的WiFi网络,试试这个方法!
Summary of the resumption of a 618 promotion project
[C + + learning notes] how about the simple use of the C + + standard library STD:: thread?
随机推荐
Dynamic programming -- state compression DP of set represented by binary
Didi's distributed ID generator (tinyid), easy to use
是时候结束 BERTology了
Using LWA and lync to simulate external test edge free single front end environment
动态规划——用二进制表示集合的状态压缩DP
利用线程通信、解决缓存穿透数据库雪崩
awk实现类sql的join操作
The JS solution cannot be executed after Ajax loads HTML
DOM节点操作
How to think in the way of computer
三步一坑五步一雷,高速成长下的技术团队怎么带?
滴滴的分布式ID生成器(Tinyid),好用的一批
Do not understand the underlying principle of database index? That's because you don't have a B tree in your heart
Awk implements SQL like join operation
Analysis of kubernetes service types: from concept to practice
Web API series (3) unified exception handling
一文详解微服务架构
From technology to management, the technology of system optimization is applied to enterprise management
Business Facade 与 Business Rule
vscode 配置