php - 拉拉维尔 4 : run multiple update query in 1 request

标签 php mysql laravel

有没有办法在 Laravel 中的单个连接中运行多个更新查询,

查询:

update users set score = score+130 where id = 12;
update users set score = score+10 where id = 10;
update users set score = score+10 where id = 14;

我尝试过:(不起作用)

DB::update("
    update users set score = score+130 where id = 12;
    update users set score = score+10 where id = 10;
    update users set score = score+10 where id = 14;
");

谢谢

最佳答案

您的案例可以通过两个查询得到解决:

DB::table('users')->where('id', 12)->increment('score', 130);
DB::table('users')->whereIn('id', [10, 14])->increment('score', 10);

关于php - 拉拉维尔 4 : run multiple update query in 1 request,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29351343/

相关文章:

PHP DOM - 剥离 span 标签,留下它们的内容

php - 学说 2 : How to search for an entity by its association's value?

mysql - 在 mysql 中创建新列以将 unix 时间转换为可读的日期和时间

php - 有没有办法选择最后一条记录然后根据关系进行过滤?

jquery - 如何修复在 Ajax 上的第二个请求中插入数据库的 0 值?

php - Laravel 关闭登录时记住我

php - 实时获取 Ratchet php中断开连接的客户端的客户端资源ID

PHP:如何保留 SOAP 响应的结构?

php - 在循环中仅将数据插入一行

mysql - 连接到 JBoss EWS 2.0 中的本地 MySQL 数据库