ori smaug has asked for the wisdom of the Perl Monks concerning the following question:

Hi all, I have a perl script running from a linux server, connecting to a SQL server 2008 and retrieving data. when ever the data is hebrew i get question marks only. I tried using decode, encode, with no success.
Your help please.
Also, when using a PHP script all works well.

The SQL INFORMATION_SCHEMA:
DATA_TYPE: nvarchar.
CHARACTER_SET_NAME: UNICODE.
COLLATION_NAME: Hebrew_CI_AI.

The code:
#!/usr/local/bin/perl -w use CGI; use DBI(); use warnings; use utf8; $q = CGI->new; $q->header(-encoding => 'UTF-8', -charset => 'UTF-8', -expires => '-1d +'); print "Content-Type: text/html; charset=UTF-8"; print $q->header; print $q->start_html(-title => 'Test Heb'); $sql = <<EOSQL; select Opportunity.AccountIdName from Opportunity; EOSQL $data_source = q/dbi:ODBC:SQLSRV/; $user = q/xxx/; $password = q/xxx/; $dbh = DBI->connect($data_source, $user, $password) or &errSub("Problem.\nCan't connect to SQL.",__LINE__,1); $dbh->{'LongReadLen'} = 25000; $dbh->{'LongTruncOk'} = 1; $dbh->do(q/SET names 'utf8'/); $sth = $dbh->prepare($sql); $sth->execute() or &errSub("Problem.\nCan't excute SQL query [$DBI::er +rstr].\nFailed search.",__LINE__,1); $rows = $sth->rows; if ($rows) { print "<pre>\n"; while ($ref = $sth->fetchrow_hashref()) { $AccountIdName = ($ref->{'AccountIdName'} || 'Null'); print "$AccountIdName\n"; } $sth->finish(); } else { $sth->finish(); next; } $dbh->disconnect; exit 0;

Replies are listed 'Best First'.
Re: perl odbc mssql encoding problem
by Anonymous Monk on Nov 11, 2019 at 10:28 UTC
      Hi, Thanks for the reply. i have installed DBD::ODBC from CPAN.