Get the App
SLTechnology News&Howtos  ›  Database  › 

Detailed explanation of Strict Mode knowledge points of MySQL Mode

Shulou Source: shulou.com Published: 2022-06-01 03:22:16 10月02日 Update

I. Strict Mode expatiates

Based on the limitations of strict mode (STRICT_TRANS_TABLES) of mysql5.0 and above:

1)。 Inserting null values into not null fields is not supported

2)。 Inserting a''value for a self-growing field is not supported, but a null value can be inserted

3)。 Default values for text fields are not supported

Look at the following code: (the first field is a self-increment field)

Sql code

$query= "insert into demo values (','$firstname','$lastname','$sex')"

The above code is only valid in non-strict mode.

Code code

$query= "insert into demo values (NULL,'$firstname','$lastname','$sex')"

The above code is valid only in strict mode. Replace the null value''with NULL.

ii. Make the database support Strict Mode

1. Make the following changes to the database structure to support strict mode:

1) set non-null default values for all not null fields, string defaults to'', numeric defaults to 0, and date defaults to '0000-00-0000: 00'

2) remove the default value of the text field

3) normalization improvement: change the title field to varchar (255) and the null field with default value to not null field.

two。 If the database structure of the installed PHP program shuts down Strict mode

1)。 One is to remove strict mode when installing mysql5.0 (including above).

Edit my.cnf and close Strict Mode:

Sql-mode= "NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"

2)。 The other is to modify the query statement. For example, in

If ($this- > dbcharset) {@ mysql_query ("SET NAMES". $this- > dbcharset);}

Later execution

Mysql_query ("SET @ @ sql_mode =''")

Make sure you are using MySQL5

The mysqli approach is similar in that it executes the

Mysqli_query ($this- > connection_id, "SET @ @ sql_mode =''")

So far, this is the end of this article on the detailed explanation of MySQL mode Strict Mode knowledge points. For more information about MySQL mode Strict Mode content, please search the previous articles or continue to browse the relevant articles below. I hope you will support me in the future!

Tags: Fields supports codes schemas data databases articles valid above that is version structure knowledge knowledge points content characters strings numeric values methods dates Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno macOS Shulou Information Shulou Technology MySQL MariaDB