2012-09-26 43 views
0

我是一位Perl中的新手,工作於一個遺留應用程序。我在我的數據庫中缺少一些特殊字符,例如ä,å,ö。此前,Mysql數據庫採用latin1歸類,現在更改爲UTF-8默認值。當我查看數據庫值時,這些字符不會改變(仍然可以獲得其他字符,å,ö,ä)。我看着Perl代碼,我發現這種編碼和字符集似乎不工作。任何幫助表示讚賞。謝謝。charset utf8無法在Perl代碼中工作

 use Encode qw/is_utf8 decode/; 
    my($q) = CGI->new(); 
    $q->charset('utf-8'); 
    $q->header(-charset => 'utf-8', -expires => '-1d') 

連接到數據庫

my($dbh) = DBI->connect($config{'dbDriver'},$config{'dbUser'},$config{'dbPass'}) or die "Kunde inte ansluta till $config{'dataSource'}: " . $DBI::errstr; 

$dbh->{'mysql_enable_utf8'} = 1; 
$dbh->do('SET NAMES utf8'); 
+0

請clearify你的結果做什麼;有使用'使用utf8'指令或不用 – PSIAlt

回答

2

嘗試在連接使用SET NAMES 'UTF-8';到數據庫。

+0

我更新了我的問題。我在設置'SET NAMES utf8'後試過了,它對我沒有任何作用。 – dotnetrocks

+0

我只知道原始的mysql語法。也許你可以添加錯誤消息(如果有的話)的問題? – Amelia

2

您應該啓用mysql_enable_utf8已連接。

my($dbh) = DBI->connect($config{'dbDriver'},$config{'dbUser'},$config{'dbPass'}, {mysql_enable_utf8 => 1}) 
    or die "Kunde inte ansluta till $config{'dataSource'}: " . $DBI::errstr; 

而且你應該有你的IO設置不當,我更喜歡使用utf8::all它:

use utf8::all;