Guest User

Untitled

a guest
Sep 1st, 2018
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. use Mojolicious::Lite;
  2. use Mojolicious::Plugin::Database;
  3.  
  4. # [...]
  5.  
  6. sub startup {
  7. my $self = shift;
  8. $self->plugin('database', {
  9. dsn => 'dbi:MySQL:dbname=y',
  10. username => $mysql_user,
  11. password => $mysql_passwd,
  12. helper => 'ydb',
  13. });
  14. };
  15.  
  16. get '/' => sub {
  17. my $c = shift;
  18. my $zz=$c->ydb->prepare("select count(*) from customers");
  19. my $total=$zz->execute();
  20. $c->ydb->bind_columns($total);
  21. $c->ydb->fetch;
  22. $c->session(customer=>$total);
  23. $c->render(template => 'index');
  24. };
  25.  
  26. use Mojolicious::Lite;
  27. use Mojo::mysql;
  28.  
  29. sub startup {
  30. my $self = shift;
  31. }
  32.  
  33. helper ydb => sub {
  34. my $c = shift ;
  35. return Mojo::mysql->strict_mode('mysql://muziek:muziek@localhost/muziek')
  36. };
  37.  
  38. get '/foo' => sub {
  39. my $c = shift ;
  40.  
  41. my $db = $c->ydb->db;
  42. my $row = $db->query("select count(*) COUNT from TITLE")->hash;
  43. $c->render(text => "Hello from /foo. count=" . $row->{COUNT} );
  44. };
  45.  
  46. app->start;
Add Comment
Please, Sign In to add comment