1
votes

I know one of the reason of using laravel query builder is it uses PDO parameter binding throughout to protect your application against SQL injection attacks. So it makes a query secure but the same thing will happen if I use something like DB::select("my raw query") thats what given in Basic usage on Laravel website. I just want to know what other advantages i will get for using Laravel Query Builder and Eloquent ORM. I am good with raw queries but if there are some great advantages of using Query Builder functions like table(), where(), orWhere() etc then i must use them.

1
more security, more readabilityKalhan.Toress
database query builder provides a convenient, fluent interface to creating and running database queries. It can be used to perform most database operations in your application, especially works on all supported database systems.Nuriddin Rashidov

1 Answers

1
votes

The major benefit of using the query builder is it abstracts you away from the language used by your storage of choice, i.e. MySQL, Oracle, SQLite, etc. If you ever switch database types, you can be stuck with a lot of refactoring raw SQL. When you are using query builder, you do not need to change the queries after migrating to a new database.