Ensure that it only tries to read the file but doesn't create a new one if it cannot be found.

Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
DL6ER
2017-08-01 20:58:28 +02:00
parent a2b1864e8d
commit c3e53c8b2d
+13 -4
View File
@@ -17,24 +17,33 @@ $data = array();
// Needs package php5-sqlite, e.g.
// sudo apt-get install php5-sqlite
class FTLDB extends SQLite3
{
function __construct()
{
$this->open("/etc/pihole/pihole-FTL.db", SQLITE3_OPEN_READONLY);
}
}
function SQLite3_connect($trytoreconnect)
{
try {
// connect to database
$db = new SQLite3('/etc/pihole/pihole-FTL.db');
return new FTLDB;
}
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);
$db = SQLite3_connect(false);
}
}
}
SQLite3_connect(true);
if(empty($db))
$db = SQLite3_connect(true);
if(!$db)
{
die("Error connecting to database");
}