O
O
Orbite2018-07-10 14:14:59
Perl
Orbite, 2018-07-10 14:14:59

How to defeat krakozyabry when inserting into a PERL database?

I get text from the database for processing in koi8r format

my $sql= 'SELECT NAMB FROM spr_banks WHERE bik='.$bik.' AND off = 0 LIMIT 1';
        my $sth= $dbh->prepare($sql) or error('CANNOT_PREPARE', 'Не могу подготовить запрос '.(DEBUG ? $sql.':<br> '.$DBI::errstr : ''));
        $sth->execute or error('CANNOT_EXECUTE', 'Не могу выполнить запрос '.(DEBUG ? $sql.':<br> '.$DBI::errstr : ''));
        my $res= $sth->fetchrow_arrayref;

Then it needs to be inserted into another table, I do:
my $name_bank= $res->[0]; 

            foreach my $m (@money_id){
                $sql="UPDATE arm_money SET number_bank_acc='$number_bank_account', name_bank='$name_bank', 
                          related_pay_info='$related_pay_info' WHERE LinkID= ".$m;
                $sth= $dbh->prepare($sql) or error('CANNOT_PREPARE', 'Не могу подготовить запрос '.(DEBUG ? $sql.':<br> 
                          '.$DBI::errstr : ''));     
                $sth->execute() or error('CANNOT_EXECUTE', 'Не могу выполнить запрос '.(DEBUG ? $sql.':<br> '.$DBI::errstr : '')); 
            }

but incomprehensible characters are inserted into the database ts╖.ts╔ts╚ts║ts╢ts╔ts╡ts╘ts╝ts╒ts╣ts╡ts╖
Everywhere the encoding is koi8r both in the tables and in the script. I've already tried everything, encode / decode, iconv, etc. nothing helps, except that one krakozyabry is replaced by another!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Ainur Valiev, 2018-07-16
@vaajnur

Isn't it easier to set the encoding to utf8 in the database settings?

G
gangabass, 2018-07-19
@gangabass

At the very beginning after connecting to the database:

$dbh->do(qq{SET NAMES 'utf8'}) or die $dbh->errstr;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question