Search code examples
perldbicgi-application

Perl - CGI::Application - Create session variables from database


I have a bunch of configuration variables stored within a database, key value pairs accessable via the following query:

select * from conf_table;

I want to load these key/value pairs into a CGI::Applicaiton session. At the moment this is manually done (so not from database, but hardcoded) via

$self->session->param( NAME => VALUE );

For a bunch of key value pairs. Is there a more sensible way do to this with DBI and some form of loop?

Thanks


Solution

  • You mean something like this?

    my $sth = $dbh->prepare("select key, value from mytable");
    $sth->execute;
    $sth->bind_columns(\(my ($key, $value)));
    while ($sth->fetch) {
      $self->session->param($key => $value);
    }