jfroebe has asked for the wisdom of the Perl Monks concerning the following question:
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
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Mason & DBI driving me nuts
by johnnywang (Priest) on Jul 31, 2006 at 19:33 UTC | |
by jfroebe (Parson) on Jul 31, 2006 at 19:47 UTC | |
by johnnywang (Priest) on Jul 31, 2006 at 20:26 UTC | |
by jfroebe (Parson) on Jul 31, 2006 at 20:30 UTC | |
Re: Mason & DBI driving me nuts
by EvanCarroll (Chaplain) on Aug 01, 2006 at 01:07 UTC | |
by doom (Deacon) on Aug 01, 2006 at 02:55 UTC | |
by EvanCarroll (Chaplain) on Aug 01, 2006 at 20:17 UTC | |
by doom (Deacon) on Aug 05, 2006 at 10:48 UTC | |
by johnnywang (Priest) on Aug 01, 2006 at 05:25 UTC | |
by EvanCarroll (Chaplain) on Aug 01, 2006 at 20:04 UTC | |
by doom (Deacon) on Aug 05, 2006 at 10:55 UTC | |
Re: Mason & DBI driving me nuts
by jZed (Prior) on Jul 31, 2006 at 19:06 UTC | |
by jfroebe (Parson) on Jul 31, 2006 at 19:17 UTC | |
by jZed (Prior) on Jul 31, 2006 at 19:33 UTC | |
by jfroebe (Parson) on Jul 31, 2006 at 19:45 UTC | |
Re: Mason & DBI driving me nuts
by philcrow (Priest) on Jul 31, 2006 at 18:59 UTC | |
by jfroebe (Parson) on Jul 31, 2006 at 19:18 UTC | |
by jfroebe (Parson) on Aug 12, 2006 at 15:25 UTC |