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. :(

Jason L. Froebe

Team Sybase member

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.