yii2 通过mysql show显示表与字段

不废话,直接上代码

/**
     * 查看数据库结构
     * @return mixed
     */
    public function actionDbSchema()
    {
        $tables = Yii::$app->db->createCommand("SHOW TABLE STATUS")->queryAll();
        foreach ($tables as $key => $table) {
            $tables[$key]['data'] = Yii::$app->db->createCommand("SHOW FULL COLUMNS FROM " . $table['Name'])->queryAll();
        }

        return $this->render('db-schema', [
            'columns' => $tables,
        ]);
    }

 

posted @ 2021-01-07 17:18  北漂生活  阅读(166)  评论(0编辑  收藏  举报