format('Y-m-d_H-i-s'); //------------------------------------------------------------------------------ // DB File Path $DBFILE = '../../../db/pialert.db'; //------------------------------------------------------------------------------ // Connect DB //------------------------------------------------------------------------------ function SQLite3_connect ($trytoreconnect) { global $DBFILE; try { // connect to database // return new SQLite3($DBFILE, SQLITE3_OPEN_READONLY); return new SQLite3($DBFILE, SQLITE3_OPEN_READWRITE); } catch (Exception $exception) { // sqlite3 throws an exception when it is unable to connect // try to reconnect one time after 3 seconds if($trytoreconnect) { echo ''; sleep(3); return SQLite3_connect(false); } } } //------------------------------------------------------------------------------ // Open DB //------------------------------------------------------------------------------ function OpenDB (...$DBPath) { global $DBFILE; global $db; // use custom path if supplied foreach ($DBPath as $path) { $DBFILE = $path; } if(strlen($DBFILE) == 0) { echo ''; die ('
Database not available
'); } $db = SQLite3_connect(true); if(!$db) { echo ''; die ('
Error connecting to the database
'); } $db->exec('PRAGMA journal_mode = wal;'); } ?>