field('id,title')->select(); return json($result); } //数据字典 public function sql() { $auth = Auth::instance(); // 检测权限 if ($auth->check('sql', Session::get('id'))) {// 第一个参数是规则名称,第二个参数是用户UID $database = 'fr_lab'; $table_result = Db::query('show tables'); $no_show_table = array(); //不需要显示的表 $no_show_field = array(); //不需要显示的字段 //取得所有的表名 foreach ($table_result as $row) { if (!in_array($row, $no_show_table)) { $tables[]['TABLE_NAME'] = $row['Tables_in_fr_lab']; } } //循环取得所有表的备注及表中列消息 foreach ($tables as $k => $v) { $sql = 'SELECT * FROM '; $sql .= 'INFORMATION_SCHEMA.TABLES '; $sql .= 'WHERE '; $sql .= "table_name = '{$v['TABLE_NAME']}' AND table_schema = '{$database}'"; $table_result = Db::query($sql); foreach ($table_result as $t) { $tables[$k]['TABLE_COMMENT'] = $t['TABLE_COMMENT']; } $sql = 'SELECT * FROM '; $sql .= 'INFORMATION_SCHEMA.COLUMNS '; $sql .= 'WHERE '; $sql .= "table_name = '{$v['TABLE_NAME']}' AND table_schema = '{$database}'"; $fields = array(); $field_result = Db::query($sql); foreach ($field_result as $t) { $fields[] = $t; } $tables[$k]['COLUMN'] = $fields; } $html = ''; //循环所有表 foreach ($tables as $k => $v) { $html .= '

'.($k + 1).'、'.$v['TABLE_COMMENT'].' ('.$v['TABLE_NAME'].')

'."\n"; $html .= ' '."\n"; $html .= ' '."\n"; $html .= ' '."\n"; $html .= ' '."\n"; $html .= ' '."\n"; $html .= ' '."\n"; $html .= ' '."\n"; $html .= ' '."\n"; $html .= ' '."\n"; $html .= ' '."\n"; foreach ($v['COLUMN'] as $f) { if (@!is_array($no_show_field[$v['TABLE_NAME']])) { $no_show_field[$v['TABLE_NAME']] = array(); } if (!in_array($f['COLUMN_NAME'], $no_show_field[$v['TABLE_NAME']])) { $html .= ' '."\n"; $html .= ' '."\n"; $html .= ' '."\n"; $html .= ' '."\n"; $html .= ' '."\n"; $html .= ' '."\n"; $html .= ' '."\n"; $html .= ' '."\n"; } } $html .= ' '."\n"; $html .= '
字段名数据类型默认值允许非空自动递增备注
'.$f['COLUMN_NAME'].''.$f['COLUMN_TYPE'].''.$f['COLUMN_DEFAULT'].''.$f['IS_NULLABLE'].''.('auto_increment' == $f['EXTRA'] ? '是' : ' ').''.$f['COLUMN_COMMENT'].'
'."\n"; } View::assign('html', $html); return View::fetch('/sql'); } return '无权访问'; } }