Reduce code duplication

Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
DL6ER
2019-04-26 17:58:27 +02:00
parent cedc59ba78
commit 8b0ee8f4fa
4 changed files with 29 additions and 99 deletions

View File

@@ -24,38 +24,8 @@ else
$GRAVITYDB = "/etc/pihole/gravity.db";
}
function SQLite3_connect($dbfile, $trytoreconnect)
{
try
{
// connect to database
return new SQLite3($dbfile, SQLITE3_OPEN_READONLY);
}
catch (Exception $exception)
{
// sqlite3 throws an exception when it is unable to connect, try to reconnect after 3 seconds
if($trytoreconnect)
{
sleep(3);
$db = SQLite3_connect($dbfile, false);
}
}
}
if(strlen($GRAVITYDB) > 0)
{
$db = SQLite3_connect($GRAVITYDB, true);
// Check if we successfully opened the database
if(!$db)
{
die("Error connecting to database");
}
}
else
{
die("No database available");
}
require("database.php");
$db = SQLite3_connect($GRAVITYDB);
function getTableContent($listname) {
global $db;