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