mysql - Laravel 中的批量更新

标签 mysql laravel-5 bulkupdate

我有一个包含多个更新查询的字符串, 示例:

$string = "UPDATE `student` SET `isams_id`=0001,`name`='stu name',`registration_id`='258911',`classid`=2,`section`='A',`house_name`='ELM',`status`=1,`updated_at`='2018-06-29 06:49:15' WHERE `registration_id`='258911'; UPDATE `student` SET `isams_id`=0002,`name`='xxx,`registration_id`='258912',`classid`=3,`section`='A',`house_name`='sss',`status`=1,`updated_at`='2018-06-29 06:49:15' WHERE `registration_id`='258912';"

像这样,我的字符串中有大约 2500 个更新查询。对于批量更新,我使用 DB::update( DB::raw($string));。但这会返回错误,例如,

SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'UPDATE `student` SET `isams_id`=0002,`name`='xxx',`registration_i' at line 1

如何解决这个问题。请帮助我。

最佳答案

嘿,你可以这样做

DB::update(DB::raw($string));

此外,您还漏掉了一个单引号。应该是这样的

$string = "UPDATE `student` SET `isams_id`=0001,`name`='stu name',`registration_id`='258911',`classid`=2,`section`='A',`house_name`='ELM',`status`=1,`updated_at`='2018-06-29 06:49:15' WHERE `registration_id`='258911'; UPDATE `student` SET `isams_id`=0002,`name`='xxx',`registration_id`='258912',`classid`=3,`section`='A',`house_name`='sss',`status`=1,`updated_at`='2018-06-29 06:49:15' WHERE `registration_id`='258912';"

关于mysql - Laravel 中的批量更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51098909/

相关文章:

ruby-on-rails - 如何基于 Rails 中的子查询 `update_all`

拉拉维尔 5 : Check if post input query exists

api - 使用 JWT(JSON Web token )设置 token 过期的 RESTful API

mysql - 拉拉维尔 5 : SELECT REPLACE() does not work

oracle - Oracle 12.1.0.2 中的批量更新?

c# - 在 C#/.NET 中执行批量更新的最快方法

MySQL 比较起始位置不同的变量

mysql - 当我打开具有 2000 万条记录的查询时,ms Access 停止工作

MySQL - 从从服务器查询并在主服务器上插入

php - 视频不流mysql php