-
-
Save epiphyllum/e9e080d08876066bda9b670491f47fca to your computer and use it in GitHub Desktop.
gbk dbi and mojolicious
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
use warnings FATAL => 'all'; | |
use lib "/home/app/perl5/lib/perl5/"; | |
use Encode; | |
use Data::Dumper; | |
use Getopt::Long; | |
use Mojolicious::Lite; | |
use XML::Hash; | |
use Data::Dumper; | |
use DBI; | |
#################################################################################################### | |
# create table test(name TEXT) | |
#################################################################################################### | |
my $dbh = DBI->connect('dbi:SQLite:citicdb'); | |
$dbh->{RaiseError} = 1; | |
my $insert_sth = $dbh->prepare("insert into test(name) values(?)"); | |
my $select_sth = $dbh->prepare("select * from test"); | |
$insert_sth->execute("中国"); | |
$select_sth->execute(); | |
my $row = $select_sth->fetchrow_hashref(); | |
print $row->{name} . "\n"; | |
get "/gbk-dbi" => sub { | |
shift->render(data => encode("gbk", decode("utf8", $row->{name}))); | |
}; | |
get "/gbk-lit" => sub { | |
shift->render(data => encode("gbk", "中国")); | |
}; | |
app->start; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
从数据库里选出的字段需要decode("utf8")下才能变成字面量