Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (2)
As of 2024-04-25 19:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found