Laravel 配置/数据库中的 strict 有什么用?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/42104412/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 15:17:38  来源:igfitidea点击:

What is the use of strict in laravel config/database?

phplaravellaravel-5.3

提问by iambegineer

I am new on laravel & today I have to turn off the strict in config/database file as I need to use group by in my SQL query. What is the use of strict in laravel config/database and by turning it off or strict = false will it affect the website? Will it make our website security weak? what is the disadvantage of turning strict off in laravel config/database Thank You in advance? :)

我是 laravel 的新手,今天我必须关闭严格的配置/数据库文件,因为我需要在我的 SQL 查询中使用 group by。在laravel 配置/数据库中使用strict 有什么用,关闭它或strict = false 会影响网站吗?它会使我们的网站安全性变弱吗?在laravel 配置/数据库中关闭严格的缺点是什么提前谢谢你?:)

回答by EddyTheDove

According to the doc:

根据文档:

Strict mode controls how MySQL handles invalid or missing values in data-change statements such as INSERT or UPDATE. A value can be invalid for several reasons. For example, it might have the wrong data type for the column, or it might be out of range. A value is missing when a new row to be inserted does not contain a value for a non-NULL column that has no explicit DEFAULT clause in its definition. (For a NULL column, NULL is inserted if the value is missing.) Strict mode also affects DDL statements such as CREATE TABLE.

严格模式控制 MySQL 如何处理数据更改语句(如 INSERT 或 UPDATE)中的无效或缺失值。由于多种原因,值可能无效。例如,它可能具有错误的列数据类型,或者可能超出范围。当要插入的新行不包含在其定义中没有显式 DEFAULT 子句的非 NULL 列的值时,缺少值。(对于 NULL 列,如果缺少值,则插入 NULL。)严格模式也会影响 DDL 语句,例如 CREATE TABLE。

Read more here: https://dev.mysql.com/doc/refman/5.7/en/sql-mode.html#sql-mode-strict

在此处阅读更多信息:https: //dev.mysql.com/doc/refman/5.7/en/sql-mode.html#sql-mode-strict

Disabling it wouldn't make your website unsecured if you handle all validations in your controllers and follow best practices like Laravel already does out of the box.

如果您在控制器中处理所有验证并遵循 Laravel 已经开箱即用的最佳实践,禁用它不会使您的网站不安全。