1. 程式人生 > >Yii2獲取指定表中的所有欄位

Yii2獲取指定表中的所有欄位

參考地址: https://blog.csdn.net/xinren369/article/details/51865424

    public function actionTableField(){
        $tableName= 'member'; (表名)
        $db       = Yii::$app->getDb();
        $table    = $db->createCommand("SHOW TABLES LIKE '".$tableName."'")->queryAll(); (獲取資料庫名字)
        $r=$db->getSchema()->getTableNames();//獲取表名
        $r=$db->getSchema()->getTableSchema($tableName); //獲取表字段名
    }