Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

zoransa's avatar

sql_mode strict => true why it is a good idea

In framework code it is done like this:

// If the "strict" option has been configured for the connection we'll enable
        // strict mode on all of these tables. This enforces some extra rules when
        // using the MySQL database system and is a quicker way to enforce them.
        if (isset($config['strict']) && $config['strict']) {
            $connection->prepare("set session sql_mode='STRICT_ALL_TABLES'")->execute();
        }

Well this is just under assumption that your server is not implementing STRICT_ALL_TABLES and you develop app where wrong data types are trimmed or automatically converted, default values implicitly set and you deploy to server where sql_mode = STRICT_ALL_TABLES and some INSERT and UPDATE statements start to brake.

Taylor could do:


// If the "strict" option has been configured for the connection we'll enable
        // strict mode on all of these tables. This enforces some extra rules when
        // using the MySQL database system and is a quicker way to enforce them.
        if (isset($config['strict']) && $config['strict']) {
            $connection->prepare("set session sql_mode='STRICT_ALL_TABLES'")->execute();
        } else {
        $connection->prepare("set session sql_mode=''")->execute();
    }

but that's dirty hack and one big problem is if your master is replicated and replication is set STRICT_ALL_TABLES you are in trouble...

Editing conf/database.php setting up strict=> true early in development can save you some headache.

0 likes
0 replies

Please or to participate in this conversation.