PageRenderTime 26ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/ASTRA_Demo_Server/udrive/home/admin/www/phpMyAdmin/libraries/storage_engines.lib.php

https://github.com/shafiqissani/ASTRA-College-Website
PHP | 339 lines | 171 code | 22 blank | 146 comment | 20 complexity | c1c9a298712bf1c2f0ea16f5fd0d5a60 MD5 | raw file
  1. <?php
  2. /* $Id: storage_engines.lib.php 8586 2006-02-19 15:36:55Z lem9 $ */
  3. // vim: expandtab sw=4 ts=4 sts=4:
  4. /**
  5. * Library for extracting information about the available storage engines
  6. */
  7. $GLOBALS['mysql_storage_engines'] = array();
  8. if (PMA_MYSQL_INT_VERSION >= 40102) {
  9. /**
  10. * For MySQL >= 4.1.2, the job is easy...
  11. */
  12. $res = PMA_DBI_query('SHOW STORAGE ENGINES');
  13. while ($row = PMA_DBI_fetch_assoc($res)) {
  14. $GLOBALS['mysql_storage_engines'][strtolower($row['Engine'])] = $row;
  15. }
  16. PMA_DBI_free_result($res);
  17. unset($res, $row);
  18. } else {
  19. /**
  20. * Emulating SHOW STORAGE ENGINES...
  21. */
  22. $GLOBALS['mysql_storage_engines'] = array(
  23. 'myisam' => array(
  24. 'Engine' => 'MyISAM',
  25. 'Support' => 'DEFAULT'
  26. ),
  27. 'merge' => array(
  28. 'Engine' => 'MERGE',
  29. 'Support' => 'YES'
  30. ),
  31. 'heap' => array(
  32. 'Engine' => 'HEAP',
  33. 'Support' => 'YES'
  34. ),
  35. 'memory' => array(
  36. 'Engine' => 'MEMORY',
  37. 'Support' => 'YES'
  38. )
  39. );
  40. $known_engines = array(
  41. 'archive' => 'ARCHIVE',
  42. 'bdb' => 'BDB',
  43. 'csv' => 'CSV',
  44. 'innodb' => 'InnoDB',
  45. 'isam' => 'ISAM',
  46. 'gemini' => 'Gemini'
  47. );
  48. $res = PMA_DBI_query('SHOW VARIABLES LIKE \'have\\_%\';');
  49. while ($row = PMA_DBI_fetch_row($res)) {
  50. $current = substr($row[0], 5);
  51. if (!empty($known_engines[$current])) {
  52. $GLOBALS['mysql_storage_engines'][$current] = array(
  53. 'Engine' => $known_engines[$current],
  54. 'Support' => $row[1]
  55. );
  56. }
  57. }
  58. PMA_DBI_free_result($res);
  59. unset($known_engines, $res, $row);
  60. }
  61. /**
  62. * Function for generating the storage engine selection
  63. *
  64. * @author rabus
  65. * @uses $GLOBALS['mysql_storage_engines']
  66. * @param string $name The name of the select form element
  67. * @param string $id The ID of the form field
  68. * @param boolean $offerUnavailableEngines
  69. * Should unavailable storage engines be offered?
  70. * @param string $selected The selected engine
  71. * @param int $indent The indentation level
  72. * @return string html selectbox
  73. */
  74. function PMA_generateEnginesDropdown($name = 'engine', $id = null,
  75. $offerUnavailableEngines = false, $selected = null, $indent = 0)
  76. {
  77. $selected = strtolower($selected);
  78. $spaces = str_repeat( ' ', $indent );
  79. $output = $spaces . '<select name="' . $name . '"'
  80. . (empty($id) ? '' : ' id="' . $id . '"') . '>' . "\n";
  81. foreach ($GLOBALS['mysql_storage_engines'] as $key => $details) {
  82. if (!$offerUnavailableEngines
  83. && ($details['Support'] == 'NO' || $details['Support'] == 'DISABLED')) {
  84. continue;
  85. }
  86. $output .= $spaces . ' <option value="' . htmlspecialchars($key). '"'
  87. . (empty($details['Comment'])
  88. ? '' : ' title="' . htmlspecialchars($details['Comment']) . '"')
  89. . ($key == $selected || (empty($selected) && $details['Support'] == 'DEFAULT')
  90. ? ' selected="selected"' : '') . '>' . "\n"
  91. . $spaces . ' ' . htmlspecialchars($details['Engine']) . "\n"
  92. . $spaces . ' </option>' . "\n";
  93. }
  94. $output .= $spaces . '</select>' . "\n";
  95. return $output;
  96. }
  97. /**
  98. * defines
  99. */
  100. define('PMA_ENGINE_SUPPORT_NO', 0);
  101. define('PMA_ENGINE_SUPPORT_DISABLED', 1);
  102. define('PMA_ENGINE_SUPPORT_YES', 2);
  103. define('PMA_ENGINE_SUPPORT_DEFAULT', 3);
  104. /**
  105. * Abstract Storage Engine Class
  106. */
  107. class PMA_StorageEngine
  108. {
  109. /**
  110. * @var string engine name
  111. */
  112. var $engine = 'dummy';
  113. /**
  114. * @var string engine title/description
  115. */
  116. var $title = 'PMA Dummy Engine Class';
  117. /**
  118. * @var string engine lang description
  119. */
  120. var $comment = 'If you read this text inside phpMyAdmin, something went wrong...';
  121. /**
  122. * @var integer engine supported by current server
  123. */
  124. var $support = PMA_ENGINE_SUPPORT_NO;
  125. /**
  126. * public static final PMA_StorageEngine getEngine()
  127. *
  128. * Loads the corresponding engine plugin, if available.
  129. *
  130. * @uses str_replace()
  131. * @uses file_exists()
  132. * @uses PMA_StorageEngine
  133. * @param string $engine The engine ID
  134. * @return object The engine plugin
  135. */
  136. function getEngine($engine)
  137. {
  138. $engine = str_replace('/', '', str_replace('.', '', $engine));
  139. if (file_exists('./libraries/engines/' . $engine . '.lib.php')
  140. && include_once('./libraries/engines/' . $engine . '.lib.php')) {
  141. $class_name = 'PMA_StorageEngine_' . $engine;
  142. $engine_object = new $class_name($engine);
  143. } else {
  144. $engine_object = new PMA_StorageEngine($engine);
  145. }
  146. return $engine_object;
  147. }
  148. /**
  149. * Constructor
  150. *
  151. * @uses $GLOBALS['mysql_storage_engines']
  152. * @uses PMA_ENGINE_SUPPORT_DEFAULT
  153. * @uses PMA_ENGINE_SUPPORT_YES
  154. * @uses PMA_ENGINE_SUPPORT_DISABLED
  155. * @uses PMA_ENGINE_SUPPORT_NO
  156. * @uses $this->engine
  157. * @uses $this->title
  158. * @uses $this->comment
  159. * @uses $this->support
  160. * @param string $engine The engine ID
  161. */
  162. function __construct($engine)
  163. {
  164. if (!empty($GLOBALS['mysql_storage_engines'][$engine])) {
  165. $this->engine = $engine;
  166. $this->title = $GLOBALS['mysql_storage_engines'][$engine]['Engine'];
  167. $this->comment =
  168. (isset($GLOBALS['mysql_storage_engines'][$engine]['Comment'])
  169. ? $GLOBALS['mysql_storage_engines'][$engine]['Comment']
  170. : '');
  171. switch ($GLOBALS['mysql_storage_engines'][$engine]['Support']) {
  172. case 'DEFAULT':
  173. $this->support = PMA_ENGINE_SUPPORT_DEFAULT;
  174. break;
  175. case 'YES':
  176. $this->support = PMA_ENGINE_SUPPORT_YES;
  177. break;
  178. case 'DISABLED':
  179. $this->support = PMA_ENGINE_SUPPORT_DISABLED;
  180. break;
  181. case 'NO':
  182. default:
  183. $this->support = PMA_ENGINE_SUPPORT_NO;
  184. }
  185. }
  186. }
  187. /**
  188. * old PHP 4 style constructor
  189. * @deprecated
  190. * @see PMA_StorageEngine::__construct()
  191. * @uses PMA_StorageEngine::__construct()
  192. * @param string $engine engine name
  193. */
  194. function PMA_StorageEngine($engine)
  195. {
  196. $this->__construct($engine);
  197. }
  198. /**
  199. * public String getTitle()
  200. *
  201. * Reveals the engine's title
  202. * @uses $this->title
  203. * @return string The title
  204. */
  205. function getTitle()
  206. {
  207. return $this->title;
  208. }
  209. /**
  210. * public String getComment()
  211. *
  212. * Fetches the server's comment about this engine
  213. * @uses $this->comment
  214. * @return string The comment
  215. */
  216. function getComment()
  217. {
  218. return $this->comment;
  219. }
  220. /**
  221. * public String getSupportInformationMessage()
  222. *
  223. * @uses $GLOBALS['strDefaultEngine']
  224. * @uses $GLOBALS['strEngineAvailable']
  225. * @uses $GLOBALS['strEngineDisabled']
  226. * @uses $GLOBALS['strEngineUnsupported']
  227. * @uses $GLOBALS['strEngineUnsupported']
  228. * @uses PMA_ENGINE_SUPPORT_DEFAULT
  229. * @uses PMA_ENGINE_SUPPORT_YES
  230. * @uses PMA_ENGINE_SUPPORT_DISABLED
  231. * @uses PMA_ENGINE_SUPPORT_NO
  232. * @uses $this->support
  233. * @uses $this->title
  234. * @uses sprintf
  235. * @return string The localized message.
  236. */
  237. function getSupportInformationMessage()
  238. {
  239. switch ($this->support) {
  240. case PMA_ENGINE_SUPPORT_DEFAULT:
  241. $message = $GLOBALS['strDefaultEngine'];
  242. break;
  243. case PMA_ENGINE_SUPPORT_YES:
  244. $message = $GLOBALS['strEngineAvailable'];
  245. break;
  246. case PMA_ENGINE_SUPPORT_DISABLED:
  247. $message = $GLOBALS['strEngineDisabled'];
  248. break;
  249. case PMA_ENGINE_SUPPORT_NO:
  250. default:
  251. $message = $GLOBALS['strEngineUnsupported'];
  252. }
  253. return sprintf($message, htmlspecialchars($this->title));
  254. }
  255. /**
  256. * public string[][] getVariables()
  257. *
  258. * Generates a list of MySQL variables that provide information about this
  259. * engine. This function should be overridden when extending this class
  260. * for a particular engine.
  261. *
  262. * @abstract
  263. * @return Array The list of variables.
  264. */
  265. function getVariables()
  266. {
  267. return array();
  268. }
  269. /**
  270. * returns string with filename for the MySQL helppage
  271. * about this storage engne
  272. *
  273. * @return string mysql helppage filename
  274. */
  275. function getMysqlHelpPage()
  276. {
  277. return $this->engine . '-storage-engine';
  278. }
  279. /**
  280. * public string getVariablesLikePattern()
  281. *
  282. * @abstract
  283. * @return string SQL query LIKE pattern
  284. */
  285. function getVariablesLikePattern()
  286. {
  287. return false;
  288. }
  289. /**
  290. * public String[] getInfoPages()
  291. *
  292. * Returns a list of available information pages with labels
  293. *
  294. * @abstract
  295. * @return array The list
  296. */
  297. function getInfoPages()
  298. {
  299. return array();
  300. }
  301. /**
  302. * public String getPage()
  303. *
  304. * Generates the requested information page
  305. *
  306. * @abstract
  307. * @param string $id The page ID
  308. *
  309. * @return string The page
  310. * boolean or false on error.
  311. */
  312. function getPage($id)
  313. {
  314. return false;
  315. }
  316. }
  317. ?>