Ejemplo n.º 1
0
 public static function open()
 {
     // attempt to connect
     try {
         self::$db = new SQLite3($_SERVER['tracker']['db_path'], SQLITE3_OPEN_READWRITE);
     } catch (Exception $e) {
         // try and remove the file if one exist, it may be corrupted
         if (file_exists($_SERVER['tracker']['db_path'])) {
             @unlink($_SERVER['tracker']['db_path']);
         }
         // attempt creation
         try {
             self::$db = new SQLite3($_SERVER['tracker']['db_path']);
         } catch (Exception $e) {
             // relay the specific error message
             tracker_error($e->getMessage() . ' - verify chmod 0777 on db directory');
         }
         // create database tables
         self::$db->exec('BEGIN TRANSACTION; ' . 'CREATE TABLE IF NOT EXISTS peers ' . '(info_hash BLOB, peer_id BLOB, compact BLOB, ip TEXT, ' . 'port INTEGER DEFAULT 0, state INTEGER DEFAULT 0, ' . 'updated INTEGER DEFAULT 0); ' . 'CREATE TABLE IF NOT EXISTS tasks' . '(name TEXT, value INTEGER DEFAULT 0); ' . 'CREATE UNIQUE INDEX IF NOT EXISTS i0 ' . 'ON peers(info_hash, peer_id); ' . 'COMMIT;') or tracker_error('failed to create database tables');
     }
     // tweak sqlite performance
     self::$db->exec('PRAGMA synchronous = OFF; ' . 'PRAGMA journal_mode = MEMORY; ' . 'PRAGMA temp_store = MEMORY;') or tracker_error('failed to set sqlite3 options');
 }
Ejemplo n.º 2
0
 public static function open()
 {
     // attempt to connect
     self::$db = pg_connect("host='{$_SERVER['tracker']['db_host']}' dbname='{$_SERVER['tracker']['db_name']}' " . "user='******'tracker']['db_user']}' password='******'tracker']['db_pass']}'") or tracker_error('database error - ' . pg_last_error(self::$db));
 }