IndexController.class.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <?php
  2. namespace Home\Controller;
  3. use Think\Controller;
  4. class IndexController extends Controller {
  5. public function index() {
  6. $tables = M ( 'profiling' )->query ( "show databases" );
  7. // print_r($tables);
  8. $this->assign ( "tables", $tables );
  9. $this->display ();
  10. }
  11. public function table() {
  12. $t1 = microtime ( true );
  13. header ( "Content-type: text/html; charset=utf-8" );
  14. $table = request ( "table" );
  15. $this->assign ( "table", $table );
  16. $condition ['table_schema'] = $table;
  17. $where = "table_schema='" . $table . "'";
  18. $tables = M ( 'tables' )->where ( $where )->order ( "table_name asc" )->select ();
  19. // 第一种方式
  20. $columns = M ( 'columns' )->where ( $where )->order ( "table_name asc,ordinal_position asc,column_name asc" )->select ();
  21. // print_r($columns);
  22. foreach ( $tables as $k => $v ) {
  23. $i=0;
  24. foreach ( $columns as $kk => $vv ) {
  25. if ($v ['table_name'] == $vv ['table_name']) {
  26. $i++;
  27. $tables [$k] ['column'] [$kk] = $vv;
  28. $tables [$k] ['column'] [$kk]['index']=$i;
  29. unset ( $columns [$kk] );
  30. }
  31. }
  32. }
  33. // print_r($tables);
  34. // 第二种方式
  35. // print_r($columns);
  36. // foreach ( $tables as $k => $v ) {
  37. // $tables [$k] ['column'] =M ( 'columns' )->where ( "table_schema='" . $table . "' and table_name='".$v['table_name']."'" )->order ( "table_name asc,ordinal_position asc,column_name asc" )->select ();
  38. // }
  39. // print_r($tables);
  40. $this->assign ( "tables", $tables );
  41. $this->display ();
  42. $t2 = microtime(true);
  43. echo '耗时'.round($t2-$t1,3).'秒';
  44. }
  45. }