I’m new to Mason and am having trouble printing a simple html table pulling data from a table on a database. I know this has to do with scope but there has to be an easier way other than putting the entire dbms call (including printing the table) within a perl code section.
One thing I have noticed is the apparent lack of any useful information of using Mason with DBI connections.
This is how you do it if you wanted a single file to connect to the dbms and then spit out the result set:
my %serverDump;
my $dbh = DBI->connect("dbi:Sybase:server=mydb", ‘info’, ‘infopwd’, { RaiseError => 1, PrintError => 1 } );
$dbh->do("use sybase_dba");
my $query = "select serverName, min(dumpdate) from dbLastBackup group by serverName";
my $sth = $dbh->prepare($query);
$sth->execute or die "Error: unable to run query! " . $dbh->errstr;
<table Border=1>
% while (my $row = $sth->fetchrow_arrayref ) {
<tr>
<td>< % $row->[0] %></td><td>< % $row->[1] %></td>
</tr>
% }
</table>
Note, don’t forget to uncomment "PerlSetVar MasonErrorMode fatal". For some reason, no errors were being sent to the browser.




August 31st, 2006 at 9:37 pm
Keep up the great work on your blog. Best wishes WaltDe