Skip to content

Instantly share code, notes, and snippets.

@pandanote-info
Last active January 27, 2021 10:20
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 pandanote-info/6b193f5f544dc894d358c0bd88f4fa8d to your computer and use it in GitHub Desktop.
Save pandanote-info/6b193f5f544dc894d358c0bd88f4fa8d to your computer and use it in GitHub Desktop.
#!/usr/bin/perl
# See https://pandanote.info/?p=7242 for details.
package ServerStatus;
use strict;
use warnings;
use DBI;
sub getStatus {
my $dbh = DBI->connect('DBI:MariaDB:database=serverstatus;host=localhost',
'serverstatus', 'Some password to store the status of remote server.',
{ RaiseError => 1, PrintError => 0 });
my $sth = $dbh->prepare('SELECT status FROM serverstatus order by id desc limit 0,1');
$sth->execute();
my $status = 0;
while (my $ref = $sth->fetchrow_hashref()) {
$status = $ref->{'status'};
}
# Disconnect from the database.
$dbh->disconnect();
return $status;
}
1;
__END__
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment