Add link to wiki explaining configuration options.
[phpmyadmin/crack.git] / libraries / storage_engines.lib.php
bloba73ce028154c1b15098c6621bf670e08eee5e0a7
1 <?php
2 /* $Id$ */
3 // vim: expandtab sw=4 ts=4 sts=4:
5 /**
6 * Library for extracting information about the available storage engines
7 */
9 $GLOBALS['mysql_storage_engines'] = array();
11 if (PMA_MYSQL_INT_VERSION >= 40102) {
12 /**
13 * For MySQL >= 4.1.2, the job is easy...
15 $res = PMA_DBI_query('SHOW STORAGE ENGINES');
16 while ($row = PMA_DBI_fetch_assoc($res)) {
17 $GLOBALS['mysql_storage_engines'][strtolower($row['Engine'])] = $row;
19 PMA_DBI_free_result($res);
20 unset($res, $row);
21 } else {
22 /**
23 * Emulating SHOW STORAGE ENGINES...
25 $GLOBALS['mysql_storage_engines'] = array(
26 'myisam' => array(
27 'Engine' => 'MyISAM',
28 'Support' => 'DEFAULT'
30 'merge' => array(
31 'Engine' => 'MERGE',
32 'Support' => 'YES'
34 'heap' => array(
35 'Engine' => 'HEAP',
36 'Support' => 'YES'
38 'memory' => array(
39 'Engine' => 'MEMORY',
40 'Support' => 'YES'
43 $known_engines = array(
44 'archive' => 'ARCHIVE',
45 'bdb' => 'BDB',
46 'csv' => 'CSV',
47 'innodb' => 'InnoDB',
48 'isam' => 'ISAM',
49 'gemini' => 'Gemini'
51 $res = PMA_DBI_query('SHOW VARIABLES LIKE \'have\\_%\';');
52 while ($row = PMA_DBI_fetch_row($res)) {
53 $current = substr($row[0], 5);
54 if (!empty($known_engines[$current])) {
55 $GLOBALS['mysql_storage_engines'][$current] = array(
56 'Engine' => $known_engines[$current],
57 'Support' => $row[1]
61 PMA_DBI_free_result($res);
62 unset($known_engines, $res, $row);
65 /**
66 * Function for generating the storage engine selection
68 * @author rabus
69 * @uses $GLOBALS['mysql_storage_engines']
70 * @param string $name The name of the select form element
71 * @param string $id The ID of the form field
72 * @param boolean $offerUnavailableEngines
73 * Should unavailable storage engines be offered?
74 * @param string $selected The selected engine
75 * @param int $indent The indentation level
76 * @return string html selectbox
78 function PMA_generateEnginesDropdown($name = 'engine', $id = null,
79 $offerUnavailableEngines = false, $selected = null, $indent = 0)
81 $selected = strtolower($selected);
82 $spaces = str_repeat( ' ', $indent );
83 $output = $spaces . '<select name="' . $name . '"'
84 . (empty($id) ? '' : ' id="' . $id . '"') . '>' . "\n";
86 foreach ($GLOBALS['mysql_storage_engines'] as $key => $details) {
87 if (!$offerUnavailableEngines
88 && ($details['Support'] == 'NO' || $details['Support'] == 'DISABLED')) {
89 continue;
91 $output .= $spaces . ' <option value="' . htmlspecialchars($key). '"'
92 . (empty($details['Comment'])
93 ? '' : ' title="' . htmlspecialchars($details['Comment']) . '"')
94 . ($key == $selected || (empty($selected) && $details['Support'] == 'DEFAULT')
95 ? ' selected="selected"' : '') . '>' . "\n"
96 . $spaces . ' ' . htmlspecialchars($details['Engine']) . "\n"
97 . $spaces . ' </option>' . "\n";
99 $output .= $spaces . '</select>' . "\n";
100 return $output;
104 * defines
106 define('PMA_ENGINE_SUPPORT_NO', 0);
107 define('PMA_ENGINE_SUPPORT_DISABLED', 1);
108 define('PMA_ENGINE_SUPPORT_YES', 2);
109 define('PMA_ENGINE_SUPPORT_DEFAULT', 3);
112 * Abstract Storage Engine Class
114 class PMA_StorageEngine
117 * @var string engine name
119 var $engine = 'dummy';
122 * @var string engine title/description
124 var $title = 'PMA Dummy Engine Class';
127 * @var string engine lang description
129 var $comment = 'If you read this text inside phpMyAdmin, something went wrong...';
132 * @var integer engine supported by current server
134 var $support = PMA_ENGINE_SUPPORT_NO;
137 * public static final PMA_StorageEngine getEngine()
139 * Loads the corresponding engine plugin, if available.
141 * @uses str_replace()
142 * @uses file_exists()
143 * @uses PMA_StorageEngine
144 * @param string $engine The engine ID
145 * @return object The engine plugin
147 function getEngine($engine)
149 $engine = str_replace('/', '', str_replace('.', '', $engine));
150 if (file_exists('./libraries/engines/' . $engine . '.lib.php')
151 && include_once('./libraries/engines/' . $engine . '.lib.php')) {
152 $class_name = 'PMA_StorageEngine_' . $engine;
153 $engine_object = new $class_name($engine);
154 } else {
155 $engine_object = new PMA_StorageEngine($engine);
157 return $engine_object;
161 * Constructor
163 * @uses $GLOBALS['mysql_storage_engines']
164 * @uses PMA_ENGINE_SUPPORT_DEFAULT
165 * @uses PMA_ENGINE_SUPPORT_YES
166 * @uses PMA_ENGINE_SUPPORT_DISABLED
167 * @uses PMA_ENGINE_SUPPORT_NO
168 * @uses $this->engine
169 * @uses $this->title
170 * @uses $this->comment
171 * @uses $this->support
172 * @param string $engine The engine ID
174 function __construct($engine)
176 if (!empty($GLOBALS['mysql_storage_engines'][$engine])) {
177 $this->engine = $engine;
178 $this->title = $GLOBALS['mysql_storage_engines'][$engine]['Engine'];
179 $this->comment =
180 (isset($GLOBALS['mysql_storage_engines'][$engine]['Comment'])
181 ? $GLOBALS['mysql_storage_engines'][$engine]['Comment']
182 : '');
183 switch ($GLOBALS['mysql_storage_engines'][$engine]['Support']) {
184 case 'DEFAULT':
185 $this->support = PMA_ENGINE_SUPPORT_DEFAULT;
186 break;
187 case 'YES':
188 $this->support = PMA_ENGINE_SUPPORT_YES;
189 break;
190 case 'DISABLED':
191 $this->support = PMA_ENGINE_SUPPORT_DISABLED;
192 break;
193 case 'NO':
194 default:
195 $this->support = PMA_ENGINE_SUPPORT_NO;
201 * old PHP 4 style constructor
202 * @deprecated
203 * @see PMA_StorageEngine::__construct()
204 * @uses PMA_StorageEngine::__construct()
205 * @param string $engine engine name
207 function PMA_StorageEngine($engine)
209 $this->__construct($engine);
213 * public String getTitle()
215 * Reveals the engine's title
216 * @uses $this->title
217 * @return string The title
219 function getTitle()
221 return $this->title;
225 * public String getComment()
227 * Fetches the server's comment about this engine
228 * @uses $this->comment
229 * @return string The comment
231 function getComment()
233 return $this->comment;
237 * public String getSupportInformationMessage()
239 * @uses $GLOBALS['strDefaultEngine']
240 * @uses $GLOBALS['strEngineAvailable']
241 * @uses $GLOBALS['strEngineDisabled']
242 * @uses $GLOBALS['strEngineUnsupported']
243 * @uses $GLOBALS['strEngineUnsupported']
244 * @uses PMA_ENGINE_SUPPORT_DEFAULT
245 * @uses PMA_ENGINE_SUPPORT_YES
246 * @uses PMA_ENGINE_SUPPORT_DISABLED
247 * @uses PMA_ENGINE_SUPPORT_NO
248 * @uses $this->support
249 * @uses $this->title
250 * @uses sprintf
251 * @return string The localized message.
253 function getSupportInformationMessage()
255 switch ($this->support) {
256 case PMA_ENGINE_SUPPORT_DEFAULT:
257 $message = $GLOBALS['strDefaultEngine'];
258 break;
259 case PMA_ENGINE_SUPPORT_YES:
260 $message = $GLOBALS['strEngineAvailable'];
261 break;
262 case PMA_ENGINE_SUPPORT_DISABLED:
263 $message = $GLOBALS['strEngineDisabled'];
264 break;
265 case PMA_ENGINE_SUPPORT_NO:
266 default:
267 $message = $GLOBALS['strEngineUnsupported'];
269 return sprintf($message, htmlspecialchars($this->title));
273 * public string[][] getVariables()
275 * Generates a list of MySQL variables that provide information about this
276 * engine. This function should be overridden when extending this class
277 * for a particular engine.
279 * @abstract
280 * @return Array The list of variables.
282 function getVariables()
284 return array();
288 * returns string with filename for the MySQL helppage
289 * about this storage engne
291 * @return string mysql helppage filename
293 function getMysqlHelpPage()
295 return $this->engine . '-storage-engine';
299 * public string getVariablesLikePattern()
301 * @abstract
302 * @return string SQL query LIKE pattern
304 function getVariablesLikePattern()
306 return false;
310 * public String[] getInfoPages()
312 * Returns a list of available information pages with labels
314 * @abstract
315 * @return array The list
317 function getInfoPages()
319 return array();
323 * public String getPage()
325 * Generates the requested information page
327 * @abstract
328 * @param string $id The page ID
330 * @return string The page
331 * boolean or false on error.
333 function getPage($id)
335 return false;