Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

wahyuadepratama's avatar

How to execute multiple query in laravel ? (create myslq event, insert and update at one query)

Anybody can help me? I try to create myslq event, insert and update at one query, I using DB::raw, but I dont know how to execute it? this is my code.. how to solve that? thanks..

My code: https://gist.github.com/wahyuadepratama/32c48635e99785b4a0fe46801a1b564e

0 likes
4 replies
Snapey's avatar

before anyone answers your question, you should know that you should NEVER use string and variable concatenation in Sql queries. You are leaving yourself open to SQL injection attack.

We are trying to leave behind the perception of php being for hacky sites that are insecure... and the query appears very insecure

wahyuadepratama's avatar

Thanks @Snapey .. I will prepare my code later to improve the security ? but the main problem for me, I have execute the code at mysql and it's work perfectly. I just dont know how to excecute it with DB::raw. anybody can help me to using another method to excecute that query ?? Thanks ?

Snapey's avatar
Snapey
Best Answer
Level 122

You have to ->get() to run the query, but you should use prepared statements

wahyuadepratama's avatar

Thanks @Snapey I have solved my problem. Altough I have to separate my query into 3 statement, but it's work

Please or to participate in this conversation.