Hi,
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.
Any clues?
thanks
<%once> use DBI; </%once> <%shared> my $serverName; my $dumpdate; 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 gr +oup by serverName"; my $sth = $dbh->prepare($query); $sth->execute; $sth->bind_columns(undef, \$serverName, \$dumpdate); </%shared> <table> <th>Server Name</th><th>backup date</th> <% while ($sth->fetch) { %> <tr><td><% $serverName %></td><td><% $dumpdate %></td></tr> <% } %> </table>
Update: This is how you do it:
<%shared> 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 gr +oup by serverName"; my $sth = $dbh->prepare($query); $sth->execute or die "Error: unable to run query! " . $dbh->errstr +; </%shared> <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. :(
No one has seen what you have seen, and until that happens, we're all going to think that you're nuts. - Jack O'Neil, Stargate SG-1
In reply to Mason & DBI driving me nuts by jfroebe
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |