Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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

like image 510
iambegineer Avatar asked Feb 08 '17 03:02

iambegineer


People also ask

What is strict mode in Laravel database?

"Strict mode," which is really just the list of modes 5.7 enables by default, is comprised of the following modes: ONLY_FULL_GROUP_BY STRICT_TRANS_TABLES NO_ZERO_IN_DATE NO_ZERO_DATE ERROR_FOR_DIVISION_BY_ZERO NO_AUTO_CREATE_USER NO_ENGINE_SUBSTITUTION. You can learn more about these modes at the MySQL documentation.

Where is database configuration in Laravel?

Laravel makes connecting with databases and running queries extremely simple. The database configuration file is app/config/database. php . In this file you may define all of your database connections, as well as specify which connection should be used by default.

How check Laravel database connected or not?

Echo the Laravel database name in Blade/PHP This will output the name of the database or return 'none' if there is no connection. If you view it in the browser, it gives you the name of the connected database. Checking whether the application is connected to a Laravel database.


1 Answers

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.

Read more here: 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.

like image 151
EddyTheDove Avatar answered Nov 15 '22 11:11

EddyTheDove