Hi list, first post,

I am trying to make Class::DBI and Apache::Session to use the same
database connection, and I want to have one place for the rest of the
webapplication to ask for a database handle.

I have one module named Inferno, this module has to be called by every
page and module.
The relevant parts are shown below:

#!/usr/bin/perl -w

use strict;
use Inferno::Session;
use Inferno::DBI;

package Inferno;
my $sitehandle= Inferno::DBI->db_Main();

sub new {
  my $proto = shift;
  my $class = ref($proto) || $proto;
  my $self  = {};
  $self->{sitename}   = "Wijnand's rommelzooi";
  $self->{databasename}    = 'wijnand';
  $self->{dbuser}  = 'wijnand';
  $self->{dbpass}  = 'secret';
  $self->{dbhost}  = '127.0.0.1';
  $self->{dbport}  = '5432';
  $self->{SESSION} = undef;
  $self->{ERRORS} = [];
  $self->{COOKIE} = undef;
  bless ($self, $class);
  return $self;
}

Now the relevant parts of Inferno::DBI module:

#!/usr/bin/perl

use warnings;
use strict;

package Inferno::DBI;
use base 'Class::DBI';

my $hostname='127.0.0.1';
my $dbname='wijnand';
my $username='wijnand';
my $password='secret';
my $databasetype='Pg'; # Pg is postgresql

my $dsn = "DBI:$databasetype:host=$hostname;dbname=$dbname;port=5432";
Inferno::DBI->connection('$dsn', '$username', '$password');

As you see, at this moment the module does not retreive the database
settings through the Inferno.pm

The Inferno::Session module is not relevant, since the main problem I
am now trying to solve is to get a $dbh variable
($Inferno::sitehandle). When I get that one the Session module will
work.

I am running this in mod_perl, but I get a Internal Server error. The
only error I see  in the logs is:
[Mon May  9 22:32:13 2005] [error] Can't connect to data source $dsn,
no database driver specified and DBI_DSN env var not set at
/usr/local/libdata/perl5/site_perl/Ima/DBI.pm line 316\nCompilation
failed in require at /htdocs/index.pl line 7.\nBEGIN
failed--compilation aborted at /htdocs/index.pl line 7.\n
And that error does not give me enought hints to solve this.
The error goes away when I remove the 
my $sitehandle= Inferno::DBI->db_Main();
line from Inferno.pm.

So, how can I accomplish what I want?
If this is the wrong list then please tell me, but I think it is a
newbie question of someone who is missing something really obvious.

Regards,
Wijnand

--
A: Because it messes up the order in which people normally read text.
Q: Why is top-posting such a bad thing?
A: Top-posting.
Q: What is the most annoying thing in e-mail?

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to