/** * public: constructor - see top of this file for cache type and cache_options * * @param type $host * @param type $database * @param type $username * @param type $password * @param type $table * * @throws Exception */ public function __construct($host, $database, $username, $password, $table = 'getid3_cache') { // Check for mysql support if (!function_exists('mysql_pconnect')) { throw new DefaultException('PHP not compiled with mysql support.'); } // Connect to database $this->connection = mysql_pconnect($host, $username, $password); if (!$this->connection) { throw new DefaultException('mysql_pconnect() failed - check permissions and spelling.'); } // Select database if (!mysql_select_db($database, $this->connection)) { throw new DefaultException('Cannot use database ' . $database); } // Set table $this->table = $table; // Create cache table if not exists $this->create_table(); // Check version number and clear cache if changed $version = ''; if ($this->cursor = mysql_query('SELECT `value` FROM `' . mysql_real_escape_string($this->table) . "` WHERE (`filename` = '" . mysql_real_escape_string(GetId3Core::VERSION) . "') AND (`filesize` = '-1') AND (`filetime` = '-1') AND (`analyzetime` = '-1')", $this->connection)) { list($version) = mysql_fetch_array($this->cursor); } if ($version != GetId3Core::VERSION) { $this->clear_cache(); } parent::__construct(); }
/** * public: constructor - see top of this file for cache type and cache_options * * @param type $cache_type * @param type $dbm_filename * @param type $lock_filename * * @throws Exception */ public function __construct($cache_type, $dbm_filename, $lock_filename) { // Check for dba extension if (!extension_loaded('dba')) { throw new DefaultException('PHP is not compiled with dba support, required to use DBM style cache.'); } // Check for specific dba driver if (!function_exists('dba_handlers') || !in_array($cache_type, dba_handlers())) { throw new DefaultException('PHP is not compiled --with ' . $cache_type . ' support, required to use DBM style cache.'); } // Create lock file if needed if (!file_exists($lock_filename)) { if (!touch($lock_filename)) { throw new DefaultException('failed to create lock file: ' . $lock_filename); } } // Open lock file for writing if (!is_writable($lock_filename)) { throw new DefaultException('lock file: ' . $lock_filename . ' is not writable'); } $this->lock = fopen($lock_filename, 'w'); // Acquire exclusive write lock to lock file flock($this->lock, LOCK_EX); // Create dbm-file if needed if (!file_exists($dbm_filename)) { if (!touch($dbm_filename)) { throw new DefaultException('failed to create dbm file: ' . $dbm_filename); } } // Try to open dbm file for writing $this->dba = dba_open($dbm_filename, 'w', $cache_type); if (!$this->dba) { // Failed - create new dbm file $this->dba = dba_open($dbm_filename, 'n', $cache_type); if (!$this->dba) { throw new DefaultException('failed to create dbm file: ' . $dbm_filename); } // Insert GetId3 version number dba_insert(GetId3Core::VERSION, GetId3Core::VERSION, $this->dba); } // Init misc values $this->cache_type = $cache_type; $this->dbm_filename = $dbm_filename; // Register destructor register_shutdown_function(array($this, '__destruct')); // Check version number and clear cache if changed if (dba_fetch(GetId3Core::VERSION, $this->dba) != GetId3Core::VERSION) { $this->clear_cache(); } parent::__construct(); }
/** * __construct() * * @param string $table holds name of sqlite table * * @return type */ public function __construct($table = 'getid3_cache', $hide = false) { $this->table = $table; // Set table $file = dirname(__FILE__) . '/' . basename(__FILE__, 'php') . 'sqlite'; if ($hide) { $file = dirname(__FILE__) . '/.ht.' . basename(__FILE__, 'php') . 'sqlite'; } $this->db = new self($file); $db = $this->db; $this->create_table(); // Create cache table if not exists $version = ''; $sql = $this->version_check; $stmt = $db->prepare($sql); $stmt->bindValue(':filename', GetId3Core::VERSION, SQLITE3_TEXT); $result = $stmt->execute(); list($version) = $result->fetchArray(); if ($version != GetId3Core::VERSION) { // Check version number and clear cache if changed $this->clear_cache(); } return parent::__construct(); }