Use utf8mb4 for database operations the plugin I'm currently working on has to store user inputs which might contain 4 byte unicode characters like emojis. MySQL is not able to handle this with a utf-8 charset. It works if the charset of my tables is set to utf8mb4 and if I add 'charset' =&gt; 'utf8mb4' to config/db.php. Since the file config/db.php does not belong to my plugin, but to the installation of Craft itself, I'd like to not modify it. 

Alternatively, I can convert the inputs with StringHelper::encodeMb4() but then I would have to do that at every place where something from the outside enters my tables. 

Is there any pragmatic way of handling this? 

Greetings Jus
Crafts ActiveRecord has a function beforeSave

/**
 * @inheritdoc
 */
public function beforeSave($insert)
{
    foreach ($this-&gt;fields() as $attribute) {
        $this-&gt;$attribute = Db::prepareValueForDb($this-&gt;$attribute);
    }

    // Prepare the values
    $now = Db::prepareDateForDb(new \DateTime());

    if ($this-&gt;getIsNewRecord()) {
        if ($this-&gt;hasAttribute('dateCreated')) {
            $this-&gt;dateCreated = $now;
        }

        if ($this-&gt;hasAttribute('uid')) {
            $this-&gt;uid = StringHelper::UUID();
        }
    }

    if ($this-&gt;hasAttribute('dateUpdated')) {
        $this-&gt;dateUpdated = $now;
    }

    return parent::beforeSave($insert);
}


You can overwrite this method and include your StringHelper::encodeMb4() into it so every time $record-&gt;save() is executed your string will be converted