#!/usr/bin/perl use warnings; use strict; use Data::Dumper; use DBI; #connection settings my $s_db_name = 'database_name'; my $s_db_user = 'user'; my $s_db_auth = 'pass'; #hash ref for data fetching my $href_row = {}; #connection with transaction my $oref_dbh = DBI->connect('dbi:Pg:dbname=' . $s_db_name, $s_db_user, $s_db_auth, {AutoCommit => 0, RaiseError => 1}); #getting the default client encoding my $oref_sth = $oref_dbh->prepare("SHOW client_encoding;"); $oref_sth->execute; $href_row = $oref_sth->fetchrow_hashref(); print "\n Default Client Encoding: " . Dumper($href_row); #UTF8 #setting client encoding to be windows-1251 $oref_sth = $oref_dbh->prepare("SET client_encoding = 'WIN1251';"); $oref_sth->execute; #getting the current client encoding $oref_sth = $oref_dbh->prepare("SHOW client_encoding;"); $oref_sth->execute; $href_row = $oref_sth->fetchrow_hashref(); print "\n Current Client Encoding: " . Dumper($href_row); #WIN1251 #preparing the SELECT query $oref_sth = $oref_dbh->prepare(" SELECT id, name_en, host, descr_bg, descr_en FROM application;"); #executing it $oref_sth->execute; #fetching the data $href_row = $oref_sth->fetchall_hashref('id'); #rollback the current transaction $oref_dbh->rollback(); #dumping the fetched data using Data::Dumper print "\n Data: " . Dumper($href_row);