Perl HTML

The Mason approach is based on MVC, therefore you need to define the database connection within your Base.mc as follows:

<%init>
my $conn = DATABASE_NAME::DBI->conn();
my $sconn = DATABASE_NAME::DBI->session_conn();


Afterwards e.g. in your index.mi you need to define another init section in which you can execute your actual query to gather informations from your Database:

<%init>
my $dbh = Ws21::DBI->dbh();
my $sth;
my @articles;
if (!defined $.search) {
$sth = $dbh->prepare("SELECT SOME QUERY FROM DATABASE_NAME");
$sth->execute();
}

Then you are able to call this information with perl from within your html code section like this:

% for my $article (@articles) {
...
% }

For this call it is very important that you start the perl section with % at the very beginning of the line. If it will be started with leading spaces or tabs, it will throw an exception.

OperatingSystem:

ProgrammingLanguage:

Technology:

Subscribe to Perl HTML