Hi

I have the following setup:

base.epl

[- 
  $sub = Execute ({object => 'include/epl/sub.epl'}, syntax => 'EmbperlBlocks');
  $sub->dbconnect();
-]

--- HTML ---

[- Execute('*', $sub); -]

--- HTML ---

[- $sub->dbclose(); -]



sub.epl

[!

sub dbconnect {
  my $db_name         = "obelisk";
  my $db_username     = "obelisk";
  my $db_password     = "obelisk";

  my $dsn = "DBI:Pg:dbname=$db_name";
  $dbh = DBI->connect($dsn, $db_username, $db_password) or die $dbh->errstr;
}


sub dbquery {
  my ($self, $query, @bind_values) = @_;

  unless ($query) { error('','database'); }

  my $sth = $dbh->prepare($query) or die $dbh->errstr;
  $sth->execute(@bind_values) or die $dbh->errstr;
  my $result = $sth->fetchall_arrayref or die $dbh->errstr;
  $sth->finish;

  return $result;
}

.
.
.
.

!]


In my pages i then do something like this:

[- 
  $sub = $param[0]; 

  my $query = qq {
    SQLQuery
  };

  $result = $sub->dbquery($query, $bind1, $bind2);
-]




What i would like to do is put my database configuration (username, 
password etc) in a separate file. I tried making a config.epl and 
executing it before the $sub object execute. I put everything in 
$req->{xxx} I could use $req to pass the config around, but I 
couldn't figure out howto access $req in my subroutine.

I would like to do something like this:

base.epl

[- 
  Execute ('include/epl/config.epl');
  $sub = Execute ({object => 'include/epl/sub.epl'}, syntax => 'EmbperlBlocks');
  $sub->dbconnect();
-]


sub.epl

[!
sub dbconnect {
  $req = ????

  my $dsn = "DBI:Pg:dbname=$req->{db_name}";
  $dbh = DBI->connect($dsn, $req->{db_username}, $req->{db_password}) or die 
$dbh->errstr;
}
!]


All suggestions are appreciated.

/Christian




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to