helper_dbtool.php 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. /**
  3. * [Discuz!] (C)2001-2099 Comsenz Inc.
  4. * This is NOT a freeware, use is subject to license terms
  5. *
  6. * $Id: helper_dbtool.php 36319 2016-12-20 02:03:23Z nemohou $
  7. */
  8. if (!defined('IN_DISCUZ')) {
  9. exit('Access Denied');
  10. }
  11. class helper_dbtool {
  12. public static function dbversion() {
  13. $db = & DB::object();
  14. return $db->version();
  15. }
  16. public static function dbsize() {
  17. $dbsize = 0;
  18. $query = DB::query("SHOW TABLE STATUS LIKE '".getglobal('config/db/1/tablepre')."%'", 'SILENT');
  19. while($table = DB::fetch($query)) {
  20. $dbsize += $table['Data_length'] + $table['Index_length'];
  21. }
  22. return $dbsize;
  23. }
  24. public static function gettablestatus($tablename, $formatsize = true) {
  25. $status = DB::fetch_first("SHOW TABLE STATUS LIKE '".str_replace('_', '\_', $tablename)."'");
  26. if($formatsize) {
  27. $status['Data_length'] = sizecount($status['Data_length']);
  28. $status['Index_length'] = sizecount($status['Index_length']);
  29. }
  30. return $status;
  31. }
  32. public static function showtablecloumn($tablename) {
  33. $data = array();
  34. $db = &DB::object();
  35. if($db->version() > '4.1') {
  36. $query = $db->query("SHOW FULL COLUMNS FROM ".DB::table($tablename), 'SILENT');
  37. } else {
  38. $query = $db->query("SHOW COLUMNS FROM ".DB::table($tablename), 'SILENT');
  39. }
  40. while($field = @DB::fetch($query)) {
  41. $data[$field['Field']] = $field;
  42. }
  43. return $data;
  44. }
  45. public static function isexisttable($tablename) {
  46. $tablearr = array();
  47. $query = DB::query('SHOW TABLES', 'SILENT');
  48. while($table = DB::fetch($query)) {
  49. foreach($table as $value) {
  50. $tablearr[] = $value;
  51. }
  52. }
  53. if(in_array(DB::table($tablename), $tablearr)) {
  54. return true;
  55. } else {
  56. return false;
  57. }
  58. }
  59. }
  60. ?>