Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    May 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Perl, DBI and czech (ISO-8859-2)

    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 and 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

  • #2
    Regular Coder
    Join Date
    May 2005
    Posts
    296
    Thanks
    3
    Thanked 4 Times in 4 Posts
    Have you tried out the module CZ::Cstocs ?

    http://search.cpan.org/~janpaz/Cstoo...2/Cz/Cstocs.pm

    See if it helps

  • #3
    New to the CF scene
    Join Date
    May 2006
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thx, but didn't really help. The problem is in the DBI-Module, cause everything is ok until the moment the script uses the DBI-Module to put / get something from the DB.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •