4

如果通过以下方式连接到MySQL

my $schema = MyDatabase::Main->connect("dbi:mysql:database=$database;host=$host",'root','', {mysql_enable_utf8 => 1});

连接强制为utf8;

连接到SQLite

my $schema = MyDatabase::Main->connect('dbi:SQLite:data/sample.db', {sqlite_unicode => 1});

连接似乎不在 utf8 中;

目的是消除在获取数据时必须使用 decode() :来自:

Mojo::ByteStream->new($cycle->type)->decode('utf-8')

至:

$cycle->type

谢谢

4

1 回答 1

9

What if you connect with this:

my $schema = MyDatabase::Main->connect(
    'dbi:SQLite:data/sample.db',
    '', # empty username
    '', # empty password
    {sqlite_unicode => 1}
);

Maybe connect() is looking for the options hash-ref as argument four without realizing that SQLite doesn't need the username and password arguments.

于 2011-02-15T05:40:40.397 回答