如何防止 Laravel 中的 SQL 注入? [英] How to prevent SQL injection in Laravel?

查看:53
本文介绍了如何防止 Laravel 中的 SQL 注入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的控制器中我有这个代码:

In my controller I have this code:

public function create($brand_id)
{
    Brand::findOrFail($brand_id);
}

还有这个:

public function search() 
{
    $q = Input::get('q');
    $brands = Brand::where('title', 'LIKE', '%'.$q.'%')->take(80)->get();

这段代码安全吗?安全"是指 SQL 注入安全.或者我应该在这里做一些变量清理吗?清理用户输入的最佳方法是什么?非常感谢你帮助我:)

Is this code safe? By "safe" I mean SQL injection safe. Or should I do some variable clean up here? And what is the best way for cleaning up user input? Thanks a lot for helping me :)

推荐答案

是的,Eloquent 在后台使用参数绑定,可以安全地转义 where() 中使用的任何输入.

yes Eloquent uses parameter binding behind the scene, which safely escapes any input used in where().

这篇关于如何防止 Laravel 中的 SQL 注入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆