Try to reconnect to database if first attempt failed

Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
DL6ER
2017-07-20 20:13:05 +02:00
parent 0db3303017
commit a2b1864e8d

View File

@@ -17,19 +17,27 @@ $data = array();
// Needs package php5-sqlite, e.g.
// sudo apt-get install php5-sqlite
$db = new SQLite3('/etc/pihole/pihole-FTL.db');
if(!$db)
die("Cannot access database");
function SQLite3_connect($trytoreconnect)
{
try {
// connect to database
$db = new SQLite3('/etc/pihole/pihole-FTL.db');
}
catch (Exception $exception) {
// sqlite3 throws an exception when it is unable to connect, try to reconnect after 3 seconds
if($trytoreconnect)
{
sleep(3);
SQLite3_connect(false);
}
}
}
SQLite3_connect(true);
// Long-Term API functions
// if (isset($_GET['test']))
// {
// // $results = $db->query('SELECT * FROM QUERIES order by TIMESTAMP ASC LIMIT 2');
// $results = $db->query('SELECT TIMESTAMP,TYPE,DOMAIN,CLIENT,STATUS FROM QUERIES order by TIMESTAMP ASC');
// echo "N=".$result->numColumns;
// while ($row = $results->fetchArray())
// var_dump($row);
// }
if(empty($db))
{
die("Error connecting to database");
}
if (isset($_GET['getAllQueries']) && $auth)
{