ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
GetId3\Extension\Cache\Mysql Class Reference

GetId3() by James Heinrich info@.nosp@m.geti.nosp@m.d3.or.nosp@m.g //. More...

+ Inheritance diagram for GetId3\Extension\Cache\Mysql:
+ Collaboration diagram for GetId3\Extension\Cache\Mysql:

Public Member Functions

 __construct ($host, $database, $username, $password, $table='getid3_cache')
 public: constructor - see top of this file for cache type and cache_options More...
 
 clear_cache ()
 public: clear cache More...
 
 analyze ($filename)
 public: analyze file More...
 
- Public Member Functions inherited from GetId3\GetId3Core
 __construct ()
 public: constructor More...
 
 version ()
 
 fread_buffer_size ()
 
 setOption ($optArray)
 public: setOption More...
 
 openfile ($filename)
 
 analyze ($filename)
 public: analyze file More...
 
 GetFileFormatArray ()
 array $format_info More...
 
 GetFileFormat (&$filedata, $filename='')
 
 CharConvert (&$array, $encoding)
 
 HandleAllTags ()
 array $tags More...
 
 getHashdata ($algorithm)
 
 ChannelsBitratePlaytimeCalculations ()
 
 CalculateCompressionRatioVideo ()
 
 CalculateCompressionRatioAudio ()
 
 CalculateReplayGain ()
 
 ProcessAudioStreams ()
 
 GetId3_tempnam ()
 

Private Member Functions

 create_table ($drop=false)
 private: (re)create sql table More...
 

Private Attributes

 $cursor
 
 $connection
 

Additional Inherited Members

- Static Public Member Functions inherited from GetId3\GetId3Core
static getHelperAppsDir ()
 
static getTempDir ()
 
static environmentIsWindows ()
 
static getIncludePath ()
 
- Data Fields inherited from GetId3\GetId3Core
 $encoding = 'UTF-8'
 
 $encoding_id3v1 = 'ISO-8859-1'
 
 $option_tag_id3v1 = true
 
 $option_tag_id3v2 = true
 
 $option_tag_lyrics3 = true
 
 $option_tag_apetag = true
 
 $option_tags_process = true
 
 $option_tags_html = true
 
 $option_extra_info = true
 
 $option_save_attachments = true
 
 $option_md5_data = false
 
 $option_md5_data_source = false
 
 $option_sha1_data = false
 
 $option_max_2gb_check = null
 
 $option_fread_buffer_size = 32768
 
 $filename
 
 $fp
 
 $info
 
 $tempdir
 
const VERSION = '1.9.4-20120530'
 
const FREAD_BUFFER_SIZE = 32768
 
const ATTACHMENTS_NONE = false
 
const ATTACHMENTS_INLINE = true
 
- Protected Member Functions inherited from GetId3\GetId3Core
 setHelperAppsDir ()
 
- Protected Attributes inherited from GetId3\GetId3Core
 $startup_error = ''
 
 $startup_warning = ''
 
 $memory_limit = 0
 
- Static Protected Attributes inherited from GetId3\GetId3Core
static $TempDir
 
static $IncludePath
 
static $EnvironmentIsWindows
 
static $HelperAppsDir
 

Detailed Description

GetId3() by James Heinrich info@.nosp@m.geti.nosp@m.d3.or.nosp@m.g //.

This is a caching extension for GetId3(). It works the exact same way as the GetId3 class, but return cached information very fast

Example: (see also demo.cache.mysql.php in /demo/)

Normal GetId3 usage (example):

require_once 'getid3/getid3.php'; $getID3 = new GetId3; $getID3->encoding = 'UTF-8'; $info1 = $getID3->analyze('file1.flac'); $info2 = $getID3->analyze('file2.wv');

GetId3_cached usage:

require_once 'getid3/getid3.php'; require_once 'getid3/getid3/extension.cache.mysql.php'; // 5th parameter (tablename) is optional, default is 'getid3_cache' $getID3 = new GetId3_cached_mysql('localhost', 'database', 'username', 'password', 'tablename'); $getID3->encoding = 'UTF-8'; $info1 = $getID3->analyze('file1.flac'); $info2 = $getID3->analyze('file2.wv');

Supported Cache Types (this extension)

SQL Databases:

cache_type cache_options

mysql host, database, username, password

DBM-Style Databases: (use extension.cache.dbm)

cache_type cache_options

gdbm dbm_filename, lock_filename ndbm dbm_filename, lock_filename db2 dbm_filename, lock_filename db3 dbm_filename, lock_filename db4 dbm_filename, lock_filename (PHP5 required)

PHP must have write access to both dbm_filename and lock_filename.

Recommended Cache Types

Infrequent updates, many reads any DBM Frequent updates mysql

Author
James Heinrich info@.nosp@m.geti.nosp@m.d3.or.nosp@m.g
Allan Hansen <ahØartemis*dk>
Carlo Capocasa <calroØcarlocapocasa*com> http://www.getid3.org

Definition at line 85 of file Mysql.php.

Constructor & Destructor Documentation

◆ __construct()

GetId3\Extension\Cache\Mysql::__construct (   $host,
  $database,
  $username,
  $password,
  $table = 'getid3_cache' 
)

public: constructor - see top of this file for cache type and cache_options

Parameters
type$host
type$database
type$username
type$password
type$table
Exceptions
Exception

Definition at line 109 of file Mysql.php.

References $version, GetId3\Extension\Cache\Mysql\clear_cache(), GetId3\Extension\Cache\Mysql\create_table(), and GetId3\GetId3Core\VERSION.

110  {
111  // Check for mysql support
112  if (!function_exists('mysql_pconnect')) {
113  throw new DefaultException('PHP not compiled with mysql support.');
114  }
115 
116  // Connect to database
117  $this->connection = mysql_pconnect($host, $username, $password);
118  if (!$this->connection) {
119  throw new DefaultException('mysql_pconnect() failed - check permissions and spelling.');
120  }
121 
122  // Select database
123  if (!mysql_select_db($database, $this->connection)) {
124  throw new DefaultException('Cannot use database '.$database);
125  }
126 
127  // Set table
128  $this->table = $table;
129 
130  // Create cache table if not exists
131  $this->create_table();
132 
133  // Check version number and clear cache if changed
134  $version = '';
135  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)) {
136  list($version) = mysql_fetch_array($this->cursor);
137  }
138  if ($version != GetId3Core::VERSION) {
139  $this->clear_cache();
140  }
141 
142  parent::__construct();
143  }
create_table($drop=false)
private: (re)create sql table
Definition: Mysql.php:194
clear_cache()
public: clear cache
Definition: Mysql.php:148
+ Here is the call graph for this function:

Member Function Documentation

◆ analyze()

GetId3\Extension\Cache\Mysql::analyze (   $filename)

public: analyze file

Parameters
type$filename
Returns
type

Definition at line 160 of file Mysql.php.

References GetId3\GetId3Core\$filename, $result, and time.

161  {
162  if (file_exists($filename)) {
163 
164  // Short-hands
165  $filetime = filemtime($filename);
166  $filesize = filesize($filename);
167 
168  // Lookup file
169  $this->cursor = mysql_query("SELECT `value` FROM `".mysql_real_escape_string($this->table)."` WHERE (`filename` = '".mysql_real_escape_string($filename)."') AND (`filesize` = '".mysql_real_escape_string($filesize)."') AND (`filetime` = '".mysql_real_escape_string($filetime)."')", $this->connection);
170  if (mysql_num_rows($this->cursor) > 0) {
171  // Hit
172  list($result) = mysql_fetch_array($this->cursor);
173 
174  return unserialize(base64_decode($result));
175  }
176  }
177 
178  // Miss
179  $analysis = parent::analyze($filename);
180 
181  // Save result
182  if (file_exists($filename)) {
183  $this->cursor = mysql_query("INSERT INTO `".mysql_real_escape_string($this->table)."` (`filename`, `filesize`, `filetime`, `analyzetime`, `value`) VALUES ('".mysql_real_escape_string($filename)."', '".mysql_real_escape_string($filesize)."', '".mysql_real_escape_string($filetime)."', '".mysql_real_escape_string(time())."', '".mysql_real_escape_string(base64_encode(serialize($analysis)))."')", $this->connection);
184  }
185 
186  return $analysis;
187  }
$result
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.

◆ clear_cache()

GetId3\Extension\Cache\Mysql::clear_cache ( )

public: clear cache

Definition at line 148 of file Mysql.php.

References GetId3\GetId3Core\VERSION.

Referenced by GetId3\Extension\Cache\Mysql\__construct().

149  {
150  $this->cursor = mysql_query("DELETE FROM `".mysql_real_escape_string($this->table)."`", $this->connection);
151  $this->cursor = mysql_query("INSERT INTO `".mysql_real_escape_string($this->table)."` VALUES ('".GetId3Core::VERSION."', -1, -1, -1, '".GetId3Core::VERSION."')", $this->connection);
152  }
+ Here is the caller graph for this function:

◆ create_table()

GetId3\Extension\Cache\Mysql::create_table (   $drop = false)
private

private: (re)create sql table

Parameters
type$drop

Definition at line 194 of file Mysql.php.

Referenced by GetId3\Extension\Cache\Mysql\__construct().

195  {
196  $this->cursor = mysql_query("CREATE TABLE IF NOT EXISTS `".mysql_real_escape_string($this->table)."` (
197  `filename` VARCHAR(255) NOT NULL DEFAULT '',
198  `filesize` INT(11) NOT NULL DEFAULT '0',
199  `filetime` INT(11) NOT NULL DEFAULT '0',
200  `analyzetime` INT(11) NOT NULL DEFAULT '0',
201  `value` TEXT NOT NULL,
202  PRIMARY KEY (`filename`,`filesize`,`filetime`)) ENGINE=MyISAM", $this->connection);
203  echo mysql_error($this->connection);
204  }
+ Here is the caller graph for this function:

Field Documentation

◆ $connection

GetId3\Extension\Cache\Mysql::$connection
private

Definition at line 97 of file Mysql.php.

◆ $cursor

GetId3\Extension\Cache\Mysql::$cursor
private

Definition at line 91 of file Mysql.php.


The documentation for this class was generated from the following file: