Hi Veltro

Thanks for the suggestion. Eventually, the database handler was found with $c->app->_dbh_db(); Strange that the doc of the module does not describe this...

I'm that code, which works
use Mojolicious::Lite; use Mojolicious::Plugin::Database; use Data::Dumper; plugin 'Database' => { dsn => 'dbi:mysql:host=m...h:dbname=d....', username => 'd....r', password => '.....', options => { 'pg_enable_utf8' => 1, AutoCommit => 1, PrintErr +or =>0, RaiseError => 1 }, helper => 'db', }; get '/invtot' => sub { my $c = shift; $c->render("invtot"); }; post '/invtot' => sub { my $c = shift; my $p = $c->req->body_params->to_hash; print Dumper $p; print Dumper $c->app->_dbh_db(); my $dbh = $c->app->_dbh_db(); my $st = $dbh->prepare("SELECT * FROM jrn WHERE ti like ? ORDER BY + tri ASC") or die $dbh->errstr ; if (length $p->{'ztSearch'} > 0) { $st->execute($p->{'ztSearch'} . '%'); my $ar; while ($ar = $st->fetchrow_arrayref) { my @values = map {defined $_ ? ($_) : ('') } @$ar; print join(" ", @values), "\n"; } $st->finish; } }; app->start; __DATA__ #as above

Now, I would prefer to have my statements prepared as the start of the application, one time after the connection is made, not at each page displayed. What's the best way to do this?

frazap


In reply to Re^2: How can I get a database handler with Mojolicious::Plugin::Database by frazap
in thread How can I get a database handler with Mojolicious::Plugin::Database by frazap

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.