31.65% of SQL queries are SET NAME. It's necessary?

Looking at the database query statistics, I can see that 31.65% of SQL queries are SET options. I am using Zend Framework 2 with PDO extension. I don't use the SET parameter anywhere other than my global.php:

'db' => array(
            'driver' => 'Pdo',
            'dsn' => 'mysql:dbname=db;',
            'driver_options' => array(
                PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\''
            ),
        ),

      

Database mapping (MariaDB) - utf8_general_ci. It's necessary? Can I uninstall this driver variant? Can't it be defined in the database once and for all?

+3


source to share


1 answer


You should use this option to set the encoding of each db connection immediately after creating the connection. Database mapping is another option that does not affect the encoding of the current connection. You can skip this option if you have a guarantee that the mysql server is installed by default to work with utf8 connections, and its configuration will not change without your participation (but in this case, you may have a problem with the portability of your application). Fortunately, queries like SET NAMES ... are pretty fast.



+1


source







All Articles