当前位置:网站首页>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
边栏推荐
- The JS solution cannot be executed after Ajax loads HTML
- CPU瞒着内存竟干出这种事
- Annual salary of 900000 programmers is not as good as 3800 civil servants a month? How to choose between stability and high income?
- Vscode configuration
- 年薪90万程序员不如月入3800公务员?安稳与高收入,到底如何选择?
- Web API系列(三)统一异常处理
- 低代码 vs 模型驱动,它们之间到底是什么关系?
- 不要把异常当做业务逻辑,这性能可能你无法承受
- Exception calling 'downloadstring' with '1' arguments: 'operation timed out'
- use Xunit.DependencyInjection Transformation test project
猜你喜欢
Advanced concurrent programming series 9 (lock interface analysis)
利用线程通信、解决缓存穿透数据库雪崩
年薪90万程序员不如月入3800公务员?安稳与高收入,到底如何选择?
Don't treat exceptions as business logic, which you can't afford
A detailed explanation of microservice architecture
Classroom exercises
Ac86u KX Online
Do not understand the underlying principle of database index? That's because you don't have a B tree in your heart
不要把异常当做业务逻辑,这性能可能你无法承受
If you want to forget the WiFi network you used to connect to your Mac, try this!
随机推荐
Three steps, one pit, five steps and one thunder, how to lead the technical team under the rapid growth?
laravel8更新之维护模式改进
The CPU does this without the memory
When tidb and Flink are combined: efficient and easy to use real-time data warehouse
Using thread communication to solve the problem of cache penetrating database avalanche
Mac新手必备小技巧
Microservice - how to limit and fuse service current
Don't treat exceptions as business logic, which you can't afford
In the age of screen reading, we suffer from attention deficit syndrome
Application and principle of handlermethodargumentresolver
Using pipe() to improve code readability in pandas
DOM节点操作
建议患者自杀,OpenAI警告:GPT-3用于医疗目的风险太高
Annual salary of 900000 programmers is not as good as 3800 civil servants a month? How to choose between stability and high income?
[漫谈] 软件设计的目标和途径
使用“1”个参数调用“DownloadString”时发生异常:“操作超时”
Technical debt is a lack of real understanding of business functions- daverupert.com
Classroom exercises
DOM节点操作
awk实现类sql的join操作