ori smaug has asked for the wisdom of the Perl Monks concerning the following question:
#!/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 | |
by ori smaug (Novice) on Nov 11, 2019 at 11:41 UTC | |
by marto (Cardinal) on Nov 11, 2019 at 12:02 UTC | |
by ori smaug (Novice) on Nov 12, 2019 at 10:18 UTC | |
by ori smaug (Novice) on Nov 12, 2019 at 06:18 UTC |