Thread [MySQL, Tk] Und nochmal: utf-8-kodierte Daten in Datenbank -> Tk::Text -> Datenbank (13 answers)
Opened by pktm at 2012-02-23 15:41

pktm
 2012-02-23 20:22
#156391 #156391
User since
2003-08-07
2921 Artikel
BenutzerIn
[Homepage]
user image
Ja, es scheint einen Unterschied zu machen:

more (5.8kb):
Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!perl

use strict;
use warnings;
use utf8;
use DBI;
use Devel::Peek;
use Encode;

my $dbh = DBI->connect('DBI:mysql:ling:127.0.0.1', 'test', 'test', { mysql_enable_utf8 => 1 });
die DBI::errstr() unless $dbh;

my $stmt = qq~SELECT raw FROM files WHERE file_id = ?~;
my $sth = $dbh->prepare($stmt);
$sth->execute(1);

my $row = $sth->fetchrow_hashref();
my $raw = $row->{raw};

Dump $raw;

$raw = decode('utf8', $raw);
Dump $raw;

$raw = encode('utf8', $raw);
Dump $raw;

exit(0);

__END__


Code (perl): (dl )
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
SV = PV(0x35f7d20) at 0x32cd0a8
  REFCNT = 1
  FLAGS = (PADMY,POK,pPOK,UTF8)
  PV = 0x30ade38 "\303\244\303\266\303\274\303\237kekse!\303\252"\0 [UTF8 "\x{e4}\x{f6}\x{fc}\x{df}kekse!\x{ea}"]
  CUR = 16
  LEN = 24
SV = PVMG(0x357a958) at 0x32cd0a8
  REFCNT = 1
  FLAGS = (PADMY,POK,pPOK,UTF8)
  IV = 0
  NV = 0
  PV = 0x30a86f8 "\357\277\275\357\277\275\357\277\275\357\277\275kekse!\357\277\275"\0 [UTF8 "\x{fffd}\x{fffd}\x{fffd}\x{fffd}kekse!\x{fffd}"]
  CUR = 21
  LEN = 24
SV = PVMG(0x357a958) at 0x32cd0a8
  REFCNT = 1
  FLAGS = (PADMY,POK,pPOK)
  IV = 0
  NV = 0
  PV = 0x30ab9f8 "\357\277\275\357\277\275\357\277\275\357\277\275kekse!\357\277\275"\0
  CUR = 21
  LEN = 24


Da ich die Daten mit der falschen Notation auch eingefügt habe, dürfte ich das dann wohl nochmal machen :-(

Immerhin erstellt wurden die Tabellen mit utf-8 als Zeichensatz - sagen mir die MySQL-Tools.
http://www.intergastro-service.de (mein erstes CMS :) )

View full thread [MySQL, Tk] Und nochmal: utf-8-kodierte Daten in Datenbank -> Tk::Text -> Datenbank