📜 ⬆️ ⬇️

A quick note about utf-8 in Mojolicious

I spent a little more time than I would have liked, struggling with Unicode in my Mojo project, and now I want to share my experience in order to save you some precious minutes and nerve cells.

So, you need to make sure that:

1. Your base works in utf-8.

For example mysql:
 my $ dbh = DBI-> connect ($ dsn, $ user, $ pass, {mysql_enable_utf8 => 1});
 # either, after creating $ dbh:
 $ dbh -> {mysql_enable_utf8} = 1;
 $ dbh-> do ("set names utf8");

Now all the data that you write or read from the database will be in utf8.

2. You have the correct encoding in the database and tables

Creating a database, do not forget to write
 create database foobar default charset = utf8;

Or, when creating a table
 create table foo (id serial, name varchar (128) not null) default charset = utf8;

')
2. In all your templates at the beginning is written

% use encoding 'utf8';

upd Thanks to commenting, point number 3 is not needed

Must earn!

Source: https://habr.com/ru/post/192024/


All Articles