laravel中的mysql批量更新

zsohkypk  于 2021-06-24  发布在  Mysql
关注(0)|答案(1)|浏览(419)

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

$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

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

esyap4oy

esyap4oy1#

嘿,你可以这样做

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';"

相关问题