You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by jaybaker <ja...@fonterra.com> on 2007/05/01 04:28:33 UTC

mod_perl and DBD::Informix

I'm having a very frustrating time trying to get a database connection from
my mod_perl script using DBD::Informix.

System:
Redhat Enterprise Linux 4
IBM Informix Dynamic Server Version 10.00.UC3
Apache 2.0.52-28
mod_perl-2.0.1
DBI-1.40
DBD-Informix-2005.2-1


Stripped right down, my script now looks like this - 
  use Data::Dumper;
  use DBD::Informix;
  my $dbh = DBI->connect("dbi:Informix:$database", "$username",
"$password");
  print "Database connection = $dbh<br>";
  print "Error = $DBI::err, $DBI::errstr<br>";

And the results I get from running it are - 
  Database connection =
  Error = -25560, SQL: -25560: Environment variable INFORMIXSERVER must be
set.

If I run the same script from the command line (rather than through
mod_perl) I get a database connection quite happily. 
I've tried setting all the environment variables in the httpd.conf file - 
  SetEnv INFORMIXDIR /usr/informix
  SetEnv INFORMIXSERVER bktester
  SetEnv HOSTNAME bktester
  SetEnv ONCONFIG onconfig
  SetEnv INFORMIXC i386-glibc20-linux-gcc
  SetEnv DBCENTURY C
which doesn't seem to change anything...
If I print out contents of %ENV immediately prior to trying to connect, all
the environment variables are there and correct, but I still get the same
error. 

I am now completely at a loss...any ideas would be greatly appreciated.
Thanks
Jay
-- 
View this message in context: http://www.nabble.com/mod_perl-and-DBD%3A%3AInformix-tf3673134.html#a10263786
Sent from the mod_perl - General mailing list archive at Nabble.com.


Re: mod_perl and DBD::Informix

Posted by "Philippe M. Chiasson" <go...@ectoplasm.org>.
jaybaker wrote:
> "PerlSetEnv or PerlPassEnv is probably what you are looking for"
> 
> Tried both of those, neither seemed to help.
> The problem is, the environment variables ARE set (according to perl's %ENV
> variable) - but somehow the DBI module can't find them.

Sorry, should have read your post a second time. You have been hit by
a documented gotcha

http://perl.apache.org/docs/2.0/user/troubleshooting/troubleshooting.html#C_Libraries_Don_t_See_C__ENV__Entries_Set_by_Perl_Code

In a nutshell, in mod_perl-2.x, the _actual_ low-level C environ[] is
detached from Perl's %ENV for thread-safety reasons. So changes to %ENV
are seen just fine as long as it remains in Perl-land. As soon as it enters
the C-level of your informix libraries, it queries the _actual_ environment
and doesn't see your modifications.

The simplest solution is to use Env::C::setenv() in a startup.pl somewhere.

Cheers and hope this helps.

------------------------------------------------------------------------
Philippe M. Chiasson     GPG: F9BFE0C2480E7680 1AE53631CB32A107 88C3A5A5
http://gozer.ectoplasm.org/       m/gozer\@(apache|cpan|ectoplasm)\.org/


Re: mod_perl and DBD::Informix

Posted by jaybaker <ja...@fonterra.com>.
"PerlSetEnv or PerlPassEnv is probably what you are looking for"

Tried both of those, neither seemed to help.
The problem is, the environment variables ARE set (according to perl's %ENV
variable) - but somehow the DBI module can't find them.
Thanks
J


PerlSetEnv or PerlPassEnv is probably what you are looking for.

http://perl.apache.org/docs/2.0/user/config/config.html#C_PerlSetEnv_
http://perl.apache.org/docs/2.0/user/config/config.html#C_PerlPassEnv_

------------------------------------------------------------------------
Philippe M. Chiasson     GPG: F9BFE0C2480E7680 1AE53631CB32A107 88C3A5A5
http://gozer.ectoplasm.org/       m/gozer\@(apache|cpan|ectoplasm)\.org/


 


-- 
View this message in context: http://www.nabble.com/mod_perl-and-DBD%3A%3AInformix-tf3673134.html#a10263960
Sent from the mod_perl - General mailing list archive at Nabble.com.


Re: mod_perl and DBD::Informix

Posted by "Philippe M. Chiasson" <go...@ectoplasm.org>.
jaybaker wrote:
> I'm having a very frustrating time trying to get a database connection from
> my mod_perl script using DBD::Informix.
> 
> System:
> Redhat Enterprise Linux 4
> IBM Informix Dynamic Server Version 10.00.UC3
> Apache 2.0.52-28
> mod_perl-2.0.1
> DBI-1.40
> DBD-Informix-2005.2-1
> 
> 
> Stripped right down, my script now looks like this - 
>   use Data::Dumper;
>   use DBD::Informix;
>   my $dbh = DBI->connect("dbi:Informix:$database", "$username",
> "$password");
>   print "Database connection = $dbh<br>";
>   print "Error = $DBI::err, $DBI::errstr<br>";
> 
> And the results I get from running it are - 
>   Database connection =
>   Error = -25560, SQL: -25560: Environment variable INFORMIXSERVER must be
> set.
> 
> If I run the same script from the command line (rather than through
> mod_perl) I get a database connection quite happily. 
> I've tried setting all the environment variables in the httpd.conf file - 
>   SetEnv INFORMIXDIR /usr/informix
>   SetEnv INFORMIXSERVER bktester
>   SetEnv HOSTNAME bktester
>   SetEnv ONCONFIG onconfig
>   SetEnv INFORMIXC i386-glibc20-linux-gcc
>   SetEnv DBCENTURY C
> which doesn't seem to change anything...

PerlSetEnv or PerlPassEnv is probably what you are looking for.

http://perl.apache.org/docs/2.0/user/config/config.html#C_PerlSetEnv_
http://perl.apache.org/docs/2.0/user/config/config.html#C_PerlPassEnv_

------------------------------------------------------------------------
Philippe M. Chiasson     GPG: F9BFE0C2480E7680 1AE53631CB32A107 88C3A5A5
http://gozer.ectoplasm.org/       m/gozer\@(apache|cpan|ectoplasm)\.org/