Last active
January 27, 2021 10:20
-
-
Save pandanote-info/6b193f5f544dc894d358c0bd88f4fa8d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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