0

I have a string with multiple update queries, example:

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

Like this, I have around 2500 update queries in my string. For bulk update I am using DB::update( DB::raw($string));. But this returns error like,

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

How to resolve this. Please help me.

Arya
  • 504
  • 2
  • 8
  • 31
  • Why don't you use the [Database Query Builder](https://laravel.com/docs/5.6/queries) functionality? As far as I can see there are no statements that require a raw statement. Or from where do you get these query strings? – Kevin Jun 29 '18 at 09:59

1 Answers1

0

Hey you can do it like this

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

Also you have missed one single quote. It should be like this

$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';"
Rashmi Nalwaya
  • 486
  • 4
  • 7