mirror of
https://github.com/pi-hole/web.git
synced 2026-04-23 18:29:43 +01:00
Try to reconnect to database if first attempt failed
Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
32
api_db.php
32
api_db.php
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user