php - 为什么在 Laravel 中的 DB::select 中使用 DB::raw?

标签 php mysql laravel

当您运行查询并且没有使用 Laravel 中的流畅查询构建器时,是否必须使用函数 DB::raw

例如

$result = DB::select("SELECT * FROM users");

$result2 = DB::select(DB::raw("SELECT * FROM users"));

我在这两种情况下得到了相同的结果。那么为什么有必要使用DB::raw呢?

最佳答案

DB::raw() is used to make arbitrary SQL commands which aren't parsed any further by the query builder. They therefore can create a vector for attack via SQL injection.

检查此引用。链接,包含更多详细信息:http://fideloper.com/laravel-raw-queries

Example DB::rawDB::select

关于php - 为什么在 Laravel 中的 DB::select 中使用 DB::raw?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31821421/

相关文章:

php - 谷歌距离矩阵 - 限制国家

php - Ajax 响应中的杂散字符?

php - yii2 如何运行控制台 Controller 功能

java - Android 客户端-服务器模型

php - MySQL插入语句不会插入?

PHP Mysql内容抢先看

php - 如何在 Laravel 模型中将 String 转换为 int

java - hibernate :如何选择表中的所有行

laravel - Spatie 媒体库 - 转换后删除原件

php - 我想在 laravel 5 中用户无法分别登录用户名和密码时显示特定消息