1. Check existence of mb_string, mysql and xml extensions before installation.
[openemr.git] / phpmyadmin / libraries / StorageEngine.class.php
blob5366e727ded1fa1f32ce27c432cbcaa96a56b783
1 <?php
2 /* vim: set expandtab sw=4 ts=4 sts=4: */
3 /**
4 * Library for extracting information about the available storage engines
6 * @package PhpMyAdmin
7 */
8 if (! defined('PHPMYADMIN')) {
9 exit;
12 /**
13 * defines
15 define('PMA_ENGINE_SUPPORT_NO', 0);
16 define('PMA_ENGINE_SUPPORT_DISABLED', 1);
17 define('PMA_ENGINE_SUPPORT_YES', 2);
18 define('PMA_ENGINE_SUPPORT_DEFAULT', 3);
20 define('PMA_ENGINE_DETAILS_TYPE_PLAINTEXT', 0);
21 define('PMA_ENGINE_DETAILS_TYPE_SIZE', 1);
22 define('PMA_ENGINE_DETAILS_TYPE_NUMERIC', 2); //Has no effect yet...
23 define('PMA_ENGINE_DETAILS_TYPE_BOOLEAN', 3); // 'ON' or 'OFF'
25 /**
26 * Base Storage Engine Class
28 * @package PhpMyAdmin
30 class PMA_StorageEngine
32 /**
33 * @var string engine name
35 var $engine = 'dummy';
37 /**
38 * @var string engine title/description
40 var $title = 'PMA Dummy Engine Class';
42 /**
43 * @var string engine lang description
45 var $comment
46 = 'If you read this text inside phpMyAdmin, something went wrong...';
48 /**
49 * @var integer engine supported by current server
51 var $support = PMA_ENGINE_SUPPORT_NO;
53 /**
54 * Constructor
56 * @param string $engine The engine ID
58 public function __construct($engine)
60 $storage_engines = PMA_StorageEngine::getStorageEngines();
61 if (! empty($storage_engines[$engine])) {
62 $this->engine = $engine;
63 $this->title = $storage_engines[$engine]['Engine'];
64 $this->comment = (isset($storage_engines[$engine]['Comment'])
65 ? $storage_engines[$engine]['Comment']
66 : '');
67 switch ($storage_engines[$engine]['Support']) {
68 case 'DEFAULT':
69 $this->support = PMA_ENGINE_SUPPORT_DEFAULT;
70 break;
71 case 'YES':
72 $this->support = PMA_ENGINE_SUPPORT_YES;
73 break;
74 case 'DISABLED':
75 $this->support = PMA_ENGINE_SUPPORT_DISABLED;
76 break;
77 case 'NO':
78 default:
79 $this->support = PMA_ENGINE_SUPPORT_NO;
84 /**
85 * Returns array of storage engines
87 * @static
88 * @staticvar array $storage_engines storage engines
89 * @access public
90 * @return string[] array of storage engines
92 static public function getStorageEngines()
94 static $storage_engines = null;
96 if (null == $storage_engines) {
97 if (PMA_DRIZZLE) {
98 $sql = "SELECT
99 p.plugin_name AS Engine,
100 (CASE
101 WHEN p.plugin_name = @@storage_engine THEN 'DEFAULT'
102 WHEN p.is_active THEN 'YES'
103 ELSE 'DISABLED' END) AS Support,
104 m.module_description AS Comment
105 FROM data_dictionary.plugins p
106 JOIN data_dictionary.modules m USING (module_name)
107 WHERE p.plugin_type = 'StorageEngine'
108 AND p.plugin_name NOT IN ('FunctionEngine', 'schema')";
109 $storage_engines = $GLOBALS['dbi']->fetchResult($sql, 'Engine');
110 } else {
111 $storage_engines
112 = $GLOBALS['dbi']->fetchResult('SHOW STORAGE ENGINES', 'Engine');
116 return $storage_engines;
120 * Returns HTML code for storage engine select box
122 * @param string $name The name of the select form element
123 * @param string $id The ID of the form field
124 * @param string $selected The selected engine
125 * @param boolean $offerUnavailableEngines Should unavailable storage
126 * engines be offered?
128 * @static
129 * @return string html selectbox
131 static public function getHtmlSelect(
132 $name = 'engine', $id = null,
133 $selected = null, $offerUnavailableEngines = false
135 $selected = /*overload*/mb_strtolower($selected);
136 $output = '<select name="' . $name . '"'
137 . (empty($id) ? '' : ' id="' . $id . '"') . '>' . "\n";
139 foreach (PMA_StorageEngine::getStorageEngines() as $key => $details) {
140 // Don't show PERFORMANCE_SCHEMA engine (MySQL 5.5)
141 // Don't show MyISAM for Drizzle (allowed only for temporary tables)
142 if (! $offerUnavailableEngines
143 && ($details['Support'] == 'NO'
144 || $details['Support'] == 'DISABLED'
145 || $details['Engine'] == 'PERFORMANCE_SCHEMA')
146 || (PMA_DRIZZLE && $details['Engine'] == 'MyISAM')
148 continue;
151 $output .= ' <option value="' . htmlspecialchars($key) . '"'
152 . (empty($details['Comment'])
153 ? '' : ' title="' . htmlspecialchars($details['Comment']) . '"')
154 . (/*overload*/mb_strtolower($key) == $selected
155 || (empty($selected) && $details['Support'] == 'DEFAULT')
156 ? ' selected="selected"' : '')
157 . '>' . "\n"
158 . ' ' . htmlspecialchars($details['Engine']) . "\n"
159 . ' </option>' . "\n";
161 $output .= '</select>' . "\n";
162 return $output;
166 * Loads the corresponding engine plugin, if available.
168 * @param string $engine The engine ID
170 * @return PMA_StorageEngine|bool The engine plugin or false if not found
171 * @static
173 static public function getEngine($engine)
175 $engine = str_replace('/', '', str_replace('.', '', $engine));
176 $filename = './libraries/engines/'
177 . /*overload*/mb_strtolower($engine) . '.lib.php';
178 if (file_exists($filename) && include_once $filename) {
179 switch(/*overload*/mb_strtolower($engine)) {
180 case 'bdb':
181 return new PMA_StorageEngine_Bdb($engine);
182 case 'berkeleydb':
183 return new PMA_StorageEngine_Berkeleydb($engine);
184 case 'binlog':
185 return new PMA_StorageEngine_Binlog($engine);
186 case 'innobase':
187 return new PMA_StorageEngine_Innobase($engine);
188 case 'innodb':
189 return new PMA_StorageEngine_Innodb($engine);
190 case 'memory':
191 return new PMA_StorageEngine_Memory($engine);
192 case 'merge':
193 return new PMA_StorageEngine_Merge($engine);
194 case 'mrg_myisam':
195 return new PMA_StorageEngine_MrgMyisam($engine);
196 case 'myisam':
197 return new PMA_StorageEngine_Myisam($engine);
198 case 'ndbcluster':
199 return new PMA_StorageEngine_Ndbcluster($engine);
200 case 'pbxt':
201 return new PMA_StorageEngine_Pbxt($engine);
202 case 'performance_schema':
203 return new PMA_StorageEngine_PerformanceSchema($engine);
206 return false;
209 return new PMA_StorageEngine($engine);
213 * Returns true if given engine name is supported/valid, otherwise false
215 * @param string $engine name of engine
217 * @static
218 * @return boolean whether $engine is valid or not
220 static public function isValid($engine)
222 if ($engine == "PBMS") {
223 return true;
225 $storage_engines = PMA_StorageEngine::getStorageEngines();
226 return isset($storage_engines[$engine]);
230 * Returns as HTML table of the engine's server variables
232 * @return string The table that was generated based on the retrieved
233 * information
235 public function getHtmlVariables()
237 $odd_row = false;
238 $ret = '';
240 foreach ($this->getVariablesStatus() as $details) {
241 $ret .= '<tr class="' . ($odd_row ? 'odd' : 'even') . '">' . "\n"
242 . ' <td>' . "\n";
243 if (! empty($details['desc'])) {
244 $ret .= ' '
245 . PMA_Util::showHint($details['desc'])
246 . "\n";
248 $ret .= ' </td>' . "\n"
249 . ' <th>' . htmlspecialchars($details['title']) . '</th>'
250 . "\n"
251 . ' <td class="value">';
252 switch ($details['type']) {
253 case PMA_ENGINE_DETAILS_TYPE_SIZE:
254 $parsed_size = $this->resolveTypeSize($details['value']);
255 $ret .= $parsed_size[0] . '&nbsp;' . $parsed_size[1];
256 unset($parsed_size);
257 break;
258 case PMA_ENGINE_DETAILS_TYPE_NUMERIC:
259 $ret .= PMA_Util::formatNumber($details['value']) . ' ';
260 break;
261 default:
262 $ret .= htmlspecialchars($details['value']) . ' ';
264 $ret .= '</td>' . "\n"
265 . '</tr>' . "\n";
266 $odd_row = ! $odd_row;
269 if (! $ret) {
270 $ret = '<p>' . "\n"
271 . ' '
272 . __(
273 'There is no detailed status information available for this '
274 . 'storage engine.'
276 . "\n"
277 . '</p>' . "\n";
278 } else {
279 $ret = '<table class="data">' . "\n" . $ret . '</table>' . "\n";
282 return $ret;
286 * Returns the engine specific handling for
287 * PMA_ENGINE_DETAILS_TYPE_SIZE type variables.
289 * This function should be overridden when
290 * PMA_ENGINE_DETAILS_TYPE_SIZE type needs to be
291 * handled differently for a particular engine.
293 * @param integer $value Value to format
295 * @return string the formatted value and its unit
297 public function resolveTypeSize($value)
299 return PMA_Util::formatByteDown($value);
303 * Returns array with detailed info about engine specific server variables
305 * @return array array with detailed info about specific engine server variables
307 public function getVariablesStatus()
309 $variables = $this->getVariables();
310 $like = $this->getVariablesLikePattern();
312 if ($like) {
313 $like = " LIKE '" . $like . "' ";
314 } else {
315 $like = '';
318 $mysql_vars = array();
320 $sql_query = 'SHOW GLOBAL VARIABLES ' . $like . ';';
321 $res = $GLOBALS['dbi']->query($sql_query);
322 while ($row = $GLOBALS['dbi']->fetchAssoc($res)) {
323 if (isset($variables[$row['Variable_name']])) {
324 $mysql_vars[$row['Variable_name']]
325 = $variables[$row['Variable_name']];
326 } elseif (! $like
327 && /*overload*/mb_strpos(/*overload*/mb_strtolower($row['Variable_name']), /*overload*/mb_strtolower($this->engine)) !== 0
329 continue;
331 $mysql_vars[$row['Variable_name']]['value'] = $row['Value'];
333 if (empty($mysql_vars[$row['Variable_name']]['title'])) {
334 $mysql_vars[$row['Variable_name']]['title'] = $row['Variable_name'];
337 if (! isset($mysql_vars[$row['Variable_name']]['type'])) {
338 $mysql_vars[$row['Variable_name']]['type']
339 = PMA_ENGINE_DETAILS_TYPE_PLAINTEXT;
342 $GLOBALS['dbi']->freeResult($res);
344 return $mysql_vars;
348 * Reveals the engine's title
350 * @return string The title
352 public function getTitle()
354 return $this->title;
358 * Fetches the server's comment about this engine
360 * @return string The comment
362 public function getComment()
364 return $this->comment;
368 * Information message on whether this storage engine is supported
370 * @return string The localized message.
372 public function getSupportInformationMessage()
374 switch ($this->support) {
375 case PMA_ENGINE_SUPPORT_DEFAULT:
376 $message = __('%s is the default storage engine on this MySQL server.');
377 break;
378 case PMA_ENGINE_SUPPORT_YES:
379 $message = __('%s is available on this MySQL server.');
380 break;
381 case PMA_ENGINE_SUPPORT_DISABLED:
382 $message = __('%s has been disabled for this MySQL server.');
383 break;
384 case PMA_ENGINE_SUPPORT_NO:
385 default:
386 $message = __(
387 'This MySQL server does not support the %s storage engine.'
390 return sprintf($message, htmlspecialchars($this->title));
394 * Generates a list of MySQL variables that provide information about this
395 * engine. This function should be overridden when extending this class
396 * for a particular engine.
398 * @return array The list of variables.
400 public function getVariables()
402 return array();
406 * Returns string with filename for the MySQL helppage
407 * about this storage engine
409 * @return string MySQL help page filename
411 public function getMysqlHelpPage()
413 return $this->engine . '-storage-engine';
417 * Returns the pattern to be used in the query for SQL variables
418 * related to the storage engine
420 * @return string SQL query LIKE pattern
422 public function getVariablesLikePattern()
424 return '';
428 * Returns a list of available information pages with labels
430 * @return string[] The list
432 public function getInfoPages()
434 return array();
438 * Generates the requested information page
440 * @param string $id page id
442 * @return string html output
444 public function getPage($id)
446 if (! array_key_exists($id, $this->getInfoPages())) {
447 return '';
450 $id = 'getPage' . $id;
452 return $this->$id();