123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- <?php
- class getID3_cached_mysql extends getID3
- {
-
- var $cursor;
- var $connection;
-
- function getID3_cached_mysql($host, $database, $username, $password) {
-
- if (!function_exists('mysql_pconnect')) {
- die('PHP not compiled with mysql support.');
- }
-
- $this->connection = mysql_pconnect($host, $username, $password);
- if (!$this->connection) {
- die('mysql_pconnect() failed - check permissions and spelling.');
- }
-
- if (!mysql_select_db($database, $this->connection)) {
- die('Cannot use database '.$database);
- }
-
- $this->create_table();
-
- $this->cursor = mysql_query("SELECT `value` FROM `getid3_cache` WHERE (`filename` = '".GETID3_VERSION."') AND (`filesize` = '-1') AND (`filetime` = '-1') AND (`analyzetime` = '-1')", $this->connection);
- list($version) = @mysql_fetch_array($this->cursor);
- if ($version != GETID3_VERSION) {
- $this->clear_cache();
- }
- parent::getID3();
- }
-
- function clear_cache() {
- $this->cursor = mysql_query("DELETE FROM `getid3_cache`", $this->connection);
- $this->cursor = mysql_query("INSERT INTO `getid3_cache` VALUES ('".GETID3_VERSION."', -1, -1, -1, '".GETID3_VERSION."')", $this->connection);
- }
-
- function analyze($filename) {
- if (file_exists($filename)) {
-
- $filetime = filemtime($filename);
- $filesize = filesize($filename);
- $filenam2 = mysql_escape_string($filename);
-
- $this->cursor = mysql_query("SELECT `value` FROM `getid3_cache` WHERE (`filename`='".$filenam2."') AND (`filesize`='".$filesize."') AND (`filetime`='".$filetime."')", $this->connection);
- list($result) = @mysql_fetch_array($this->cursor);
-
- if ($result) {
- return unserialize($result);
- }
- }
-
- $result = parent::analyze($filename);
-
- if (file_exists($filename)) {
- $res2 = mysql_escape_string(serialize($result));
- $this->cursor = mysql_query("INSERT INTO `getid3_cache` (`filename`, `filesize`, `filetime`, `analyzetime`, `value`) VALUES ('".$filenam2."', '".$filesize."', '".$filetime."', '".time()."', '".$res2."')", $this->connection);
- }
- return $result;
- }
-
- function create_table($drop = false) {
- $this->cursor = mysql_query("CREATE TABLE IF NOT EXISTS `getid3_cache` (
- `filename` VARCHAR(255) NOT NULL DEFAULT '',
- `filesize` INT(11) NOT NULL DEFAULT '0',
- `filetime` INT(11) NOT NULL DEFAULT '0',
- `analyzetime` INT(11) NOT NULL DEFAULT '0',
- `value` TEXT NOT NULL,
- PRIMARY KEY (`filename`,`filesize`,`filetime`)) TYPE=MyISAM", $this->connection);
- echo mysql_error($this->connection);
- }
- }
- ?>
|