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

What is the use of strict in laravel config/database?(Laravel 配置/数据库中的 strict 有什么用?)
本文介绍了Laravel 配置/数据库中的 strict 有什么用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

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

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? :)

推荐答案

根据文档:

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

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.

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

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

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 配置/数据库中的 strict 有什么用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)