Skip to content

Instantly share code, notes, and snippets.

@yko
Created April 10, 2013 09:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yko/5353059 to your computer and use it in GitHub Desktop.
Save yko/5353059 to your computer and use it in GitHub Desktop.
package MyShinyApp;
use Mojo::Base 'Mojolicious';
use DBI;
has dbh => \&_init_dbh;
sub startup { ... }
sub _init_dbh {
my $self = shift;
my $dbh = DBI->connect(
'dbi:mysql:MyShinyDatabase', #TODO: Get db name from config
undef, undef,
{ mysql_auto_reconnect => 1,
mysql_enable_utf8 => 1,
mysql_init_command => "SET CHARACTER SET 'utf8'"
}
);
unless ($dbh) {
$self->log->fatal('Failed to connect to the database');
exit(255);
}
return $dbh;
}
1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment