MySQL Forums
Forum List  »  Perl

Perl, DBI and czech (ISO-8859-2)
Posted by: terrjie
Date: May 02, 2006 03:29AM

Hi everybody

I'm trying to set up Czech-language-support for a CMS:

I'm using MYSQL 4.1.11
DBI 1.50
perl 5.8.6

on a freeBSD server

my problem is everytime i insert or get some values with special czech-chars, i just get garbage (like č (c with this inverted "hat") turns to Ä? when updating an to ? when selecting). i've been trying and searching for several hours and i just can't get it working!

the collation of the table is set to "latin2_general_ci".

for testing I wrote this sample program:

#!/usr/bin/perl -w
use strict;
use DBI;
use CGI qw(:cgi);
use encoding 'latin2';
use Encode;
use vars qw($dbh);

DBI->trace(2);

my $test = encode("latin2", 'čar');

sqlDisconnect();
sqlConnect('DBI:mysql:testczech:localhost','user','pw');

sqlSimple("UPDATE tbl1 SET name='$test' WHERE ID='1'");

my ($test2) = sqlSelect('name','tbl1','ID=2');

print "$test2\n";

sqlDisconnect();


# SQL FUNCTIONS
# -----------------------------------------------------------------------------

sub sqlConnect {
my $dbname = shift || '';
my $dbusername = shift || '';
my $dbpassword = shift || '';

$dbh = DBI->connect($dbname, $dbusername, $dbpassword);

if (!$dbh) {

}

kill 9, $$ unless $dbh;
}

# -----------------------------------------------------------------------------

sub sqlDisconnect {

$dbh->disconnect if ($dbh);
$dbh = 0;
return 0;
}

# -----------------------------------------------------------------------------

sub sqlSimple {
my $sql = shift || '';

if (!$dbh->do($sql)) {
# ERROR

my $err=$dbh->errstr;
}
}

# -----------------------------------------------------------------------------

sub sqlSelect {
my $select = shift || '';
my $from = shift || '';
my $where = shift || '';
my $other = shift || '';

#debugMsg('sub', "sqlSelect($select, $from, $where, $other)");

my $sql="SELECT $select ";
$sql.="FROM $from " if $from;
$sql.="WHERE $where " if $where;
$sql.="$other" if $other;

#debugMsg('sql',"$sql");

my ($c)=$dbh->prepare(encode('iso-8859-2',$sql)) or die "Sql has gone to hell\n";

if(not ($c->execute())) {
# ERROR

my $err=$dbh->errstr;
debugMsg('sql', "ERROR -> $err");
return undef;
}
my (@r)=$c->fetchrow();
$c->finish();

return @r;
}

1;

can anybody give me some hints? would be GREATLY appreciated!!!

thanks
terrjie

Options: ReplyQuote


Subject
Written By
Posted
Perl, DBI and czech (ISO-8859-2)
May 02, 2006 03:29AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.