ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
getID3_cached_mysqli Class Reference

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

+ Inheritance diagram for getID3_cached_mysqli:
+ Collaboration diagram for getID3_cached_mysqli:

Public Member Functions

 __construct ($host, $database, $username, $password, $table='getid3_cache')
 
 clear_cache ()
 
 analyze ($filename, $filesize=null, $original_filename='')
 
- Public Member Functions inherited from getID3
 __construct ()
 
 version ()
 
 fread_buffer_size ()
 
 setOption ($optArray)
 
 openfile ($filename, $filesize=null)
 
 analyze ($filename, $filesize=null, $original_filename='')
 
 error ($message)
 
 warning ($message)
 
 GetFileFormatArray ()
 
 GetFileFormat (&$filedata, $filename='')
 
 CharConvert (&$array, $encoding)
 
 HandleAllTags ()
 
 getHashdata ($algorithm)
 
 ChannelsBitratePlaytimeCalculations ()
 
 CalculateCompressionRatioVideo ()
 
 CalculateCompressionRatioAudio ()
 
 CalculateReplayGain ()
 
 ProcessAudioStreams ()
 
 getid3_tempnam ()
 
 include_module ($name)
 

Private Member Functions

 create_table ($drop=false)
 

Private Attributes

 $mysqli
 
 $cursor
 

Additional Inherited Members

- Data Fields inherited from getID3
 $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 = GETID3_TEMP_DIR
 
 $memory_limit = 0
 
const VERSION = '1.9.14-201703261440'
 
const FREAD_BUFFER_SIZE = 32768
 
const ATTACHMENTS_NONE = false
 
const ATTACHMENTS_INLINE = true
 
- Protected Attributes inherited from getID3
 $startup_error = ''
 
 $startup_warning = ''
 

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.mysqli.php'; // 5th parameter (tablename) is optional, default is 'getid3_cache' $getID3 = new getID3_cached_mysqli('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

mysqli 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 mysqli

Definition at line 73 of file extension.cache.mysqli.php.

Constructor & Destructor Documentation

◆ __construct()

getID3_cached_mysqli::__construct (   $host,
  $database,
  $username,
  $password,
  $table = 'getid3_cache' 
)

Definition at line 81 of file extension.cache.mysqli.php.

81 {
82
83 // Check for mysqli support
84 if (!function_exists('mysqli_connect')) {
85 throw new Exception('PHP not compiled with mysqli support.');
86 }
87
88 // Connect to database
89 $this->mysqli = new mysqli($host, $username, $password);
90 if (!$this->mysqli) {
91 throw new Exception('mysqli_connect() failed - check permissions and spelling.');
92 }
93
94 // Select database
95 if (!$this->mysqli->select_db($database)) {
96 throw new Exception('Cannot use database '.$database);
97 }
98
99 // Set table
100 $this->table = $table;
101
102 // Create cache table if not exists
103 $this->create_table();
104
105 // Check version number and clear cache if changed
106 $version = '';
107 $SQLquery = 'SELECT `value`';
108 $SQLquery .= ' FROM `'.$this->mysqli->real_escape_string($this->table).'`';
109 $SQLquery .= ' WHERE (`filename` = \''.$this->mysqli->real_escape_string(getID3::VERSION).'\')';
110 $SQLquery .= ' AND (`filesize` = -1)';
111 $SQLquery .= ' AND (`filetime` = -1)';
112 $SQLquery .= ' AND (`analyzetime` = -1)';
113 if ($this->cursor = $this->mysqli->query($SQLquery)) {
114 list($version) = $this->cursor->fetch_array();
115 }
116 if ($version != getID3::VERSION) {
117 $this->clear_cache();
118 }
119
120 parent::__construct();
121 }
$version
Definition: build.php:27
const VERSION
Definition: getid3.php:115
$password
Definition: cron.php:14
if(empty($password)) $table
Definition: pwgen.php:24

References $password, $table, $version, create_table(), and getID3\VERSION.

+ Here is the call graph for this function:

Member Function Documentation

◆ analyze()

getID3_cached_mysqli::analyze (   $filename,
  $filesize = null,
  $original_filename = '' 
)

Reimplemented from getID3.

Definition at line 132 of file extension.cache.mysqli.php.

132 {
133
134 if (file_exists($filename)) {
135
136 // Short-hands
137 $filetime = filemtime($filename);
138 $filesize = filesize($filename);
139
140 // Lookup file
141 $SQLquery = 'SELECT `value`';
142 $SQLquery .= ' FROM `'.$this->mysqli->real_escape_string($this->table).'`';
143 $SQLquery .= ' WHERE (`filename` = \''.$this->mysqli->real_escape_string($filename).'\')';
144 $SQLquery .= ' AND (`filesize` = \''.$this->mysqli->real_escape_string($filesize).'\')';
145 $SQLquery .= ' AND (`filetime` = \''.$this->mysqli->real_escape_string($filetime).'\')';
146 $this->cursor = $this->mysqli->query($SQLquery);
147 if ($this->cursor->num_rows > 0) {
148 // Hit
149 list($result) = $this->cursor->fetch_array();
150 return unserialize(base64_decode($result));
151 }
152 }
153
154 // Miss
155 $analysis = parent::analyze($filename, $filesize, $original_filename);
156
157 // Save result
158 if (file_exists($filename)) {
159 $SQLquery = 'INSERT INTO `'.$this->mysqli->real_escape_string($this->table).'` (`filename`, `filesize`, `filetime`, `analyzetime`, `value`) VALUES (';
160 $SQLquery .= '\''.$this->mysqli->real_escape_string($filename).'\'';
161 $SQLquery .= ', \''.$this->mysqli->real_escape_string($filesize).'\'';
162 $SQLquery .= ', \''.$this->mysqli->real_escape_string($filetime).'\'';
163 $SQLquery .= ', \''.$this->mysqli->real_escape_string(time() ).'\'';
164 $SQLquery .= ', \''.$this->mysqli->real_escape_string(base64_encode(serialize($analysis))).'\')';
165 $this->cursor = $this->mysqli->query($SQLquery);
166 }
167 return $analysis;
168 }
$filename
Definition: getid3.php:105

◆ clear_cache()

getID3_cached_mysqli::clear_cache ( )

Definition at line 125 of file extension.cache.mysqli.php.

125 {
126 $this->mysqli->query('DELETE FROM `'.$this->mysqli->real_escape_string($this->table).'`');
127 $this->mysqli->query('INSERT INTO `'.$this->mysqli->real_escape_string($this->table).'` (`filename`, `filesize`, `filetime`, `analyzetime`, `value`) VALUES (\''.getID3::VERSION.'\', -1, -1, -1, \''.getID3::VERSION.'\')');
128 }

◆ create_table()

getID3_cached_mysqli::create_table (   $drop = false)
private

Definition at line 172 of file extension.cache.mysqli.php.

172 {
173 $SQLquery = 'CREATE TABLE IF NOT EXISTS `'.$this->mysqli->real_escape_string($this->table).'` (';
174 $SQLquery .= '`filename` VARCHAR(990) NOT NULL DEFAULT \'\'';
175 $SQLquery .= ', `filesize` INT(11) NOT NULL DEFAULT \'0\'';
176 $SQLquery .= ', `filetime` INT(11) NOT NULL DEFAULT \'0\'';
177 $SQLquery .= ', `analyzetime` INT(11) NOT NULL DEFAULT \'0\'';
178 $SQLquery .= ', `value` LONGTEXT NOT NULL';
179 $SQLquery .= ', PRIMARY KEY (`filename`, `filesize`, `filetime`)) ENGINE=MyISAM CHARACTER SET=latin1 COLLATE=latin1_general_ci';
180 $this->cursor = $this->mysqli->query($SQLquery);
181 echo $this->mysqli->error;
182 }

Referenced by __construct().

+ Here is the caller graph for this function:

Field Documentation

◆ $cursor

getID3_cached_mysqli::$cursor
private

Definition at line 77 of file extension.cache.mysqli.php.

◆ $mysqli

getID3_cached_mysqli::$mysqli
private

Definition at line 76 of file extension.cache.mysqli.php.


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