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

Whenever I run the following script from the command line, it works fine, but if I run it on the web server from a web browser, I get the following error in my apache error.log:

[Fri Jul 17 11:26:50 2009] [error] [client 192.168.xxx.xxx] DBI connect('my_dsn','user',...) failed: [INTERSOLV][ODBC Informix driver][Informix]Unable to load locale categories. (SQL-HY000)
#!c:/perl/bin/perl use strict; use Template; use CGI qw(fatalsToBrowser); use DBI; #use POSIX qw(locale_h); #setlocale(LC_CTYPE, "en_US.CP1252"); $CGI::POST_MAX = (1024 * 100); # max 100K posts $CGI::DISABLE_UPLOADS = 1; # no uploads my ($dbh, $sth); my $Error_Message = "\nThere Was A Problem Connecting To The Database\ +n"; my $dbusername = 'user'; my $dbpassword = 'password'; my $dsn = 'my_dsn'; my $cgi = new CGI; my $query = shift; # get command line param $query ||= $cgi->param('q') unless defined $query; # unless got comman +d line param, grab cgi param # if query param was not set, use default unless ( $query ) { $query = "none"; } $query =~ /([a-zA-Z0-9-]+)/g; $query = $1; $dbh = DBI->connect("dbi:ODBC:$dsn", $dbusername, $dbpassword, {'RaiseError' => 1, 'PrintError' => 1} ) || die "$Error_Message $DBI::errstr"; my $sql = qq{select T2.item_num c1, T1.desc_1 c1, T2.on_hand c3 from item T1, item_w T2 where T2.item_num='$query' and T1.item_num = T2.item_nu +m}; $sth = $dbh->prepare($sql); $sth->execute() || die $sth->errstr; my @results; while (my @ref = $sth->fetchrow_array) { # 0=item_num, 1=desc_1, 2=on_hand push (@results, $ref[0] . ", " . $ref[1] . ", " . $ref[2]); } $sth->finish(); $dbh->disconnect(); my $tt = Template->new({INCLUDE_PATH => '../src'}) || die Template->er +ror(), "\n"; my $vars = { results => \@results, query => $query, }; print $cgi->header(-type=>"text/html"); print $tt->process('elite_inventory.tt', $vars) || die $tt->error(), " +\n";

I tried setting the locale in perl, but that didn't help. Also, nowhere I could find where to set the locale for the ODBC Informix driver (I looked in Administrative Tools - Data Sources (ODBC)).

  • Comment on DBI connect('my_dsn','user',...) failed: [INTERSOLV][ODBC Informix driver][Informix]Unable to load locale categories. (SQL-HY000)
  • Select or Download Code

Replies are listed 'Best First'.
Re: DBI connect('my_dsn','user',...) failed: [INTERSOLV][ODBC Informix driver][Informix]Unable to load locale categories. (SQL-HY000)
by runrig (Abbot) on Jul 17, 2009 at 20:34 UTC
    Is the INFORMIXDIR environment variable set, and are the files readable by the web user (the user that the script executes under from the web)?
      yes, the file is readable by the web user (same as every other script that works) and yes the INFORMIXDIR is set (On Windows platforms, INFORMIXDIR is a registry setting rather than an environment variable.)

        I found the solution: while INFORMIXDIR was set in the registries, it also needed to be set in Apache's environment variables, along with a few others.

        I added the followings to httpd.conf:

        #INFORMIX SetEnv INFORMIXDIR "C:/informix32" SetEnv INFORMIXSERVER "server" SetEnv DELIMIDENT n SetEnv DBANSIWARN n SetEnv CLIENT_LOCAL "en_US.CP1252" SetEnv DB_LOCAL "en_US.CP1252"
        and then restarted Apache.