Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use Mojolicious::Lite;
- use Mojolicious::Plugin::Database;
- # [...]
- sub startup {
- my $self = shift;
- $self->plugin('database', {
- dsn => 'dbi:MySQL:dbname=y',
- username => $mysql_user,
- password => $mysql_passwd,
- helper => 'ydb',
- });
- };
- get '/' => sub {
- my $c = shift;
- my $zz=$c->ydb->prepare("select count(*) from customers");
- my $total=$zz->execute();
- $c->ydb->bind_columns($total);
- $c->ydb->fetch;
- $c->session(customer=>$total);
- $c->render(template => 'index');
- };
- use Mojolicious::Lite;
- use Mojo::mysql;
- sub startup {
- my $self = shift;
- }
- helper ydb => sub {
- my $c = shift ;
- return Mojo::mysql->strict_mode('mysql://muziek:muziek@localhost/muziek')
- };
- get '/foo' => sub {
- my $c = shift ;
- my $db = $c->ydb->db;
- my $row = $db->query("select count(*) COUNT from TITLE")->hash;
- $c->render(text => "Hello from /foo. count=" . $row->{COUNT} );
- };
- app->start;
Add Comment
Please, Sign In to add comment