Get list of installed columns in a table

@param  string $tableName The name of a table.

@return array  Installed columns indexed by the column name.
973299
public function getTableColumns($tableName)
    {
        $db = $this->getDb();

        $allColumns = $db->fetchAll("SHOW COLUMNS FROM " . $tableName);

        $fields = array();
        foreach ($allColumns as $column) {
            $fields[trim($column['Field'])] = $column;
        }

        return $fields;
    }
80207
public function getInstalledTables()
    {
        if ($this->installedTables !== null) {
            return $this->installedTables;
        }

        /** @var $tables \Doctrine\DBAL\Schema\Table[] */
        $tables = $this->connection->getSchemaManager()->listTables();
        foreach ($tables as $table) {
            $alias = str_replace($this->app['schema.prefix'], '', $table->getName());
            $this->installedTables[$alias] = $table;
        }

        return $this->installedTables;
    }
1144360
public function getForeignKeysReferencingTable($tableName)
    {
        $matches = [];
        foreach ($this->foreignKeys as $fk) {
            if ($fk->getForeignTableName() === $tableName) {
                $matches[] = $fk;
            }
        }

        return $matches;
    }
1094821
protected function getColumns($tableName): array
    {
        $sql = sprintf('SELECT * FROM information_schema.columns
                    WHERE table_schema=database()
                    AND table_name = %s', $this->quote($tableName));

        $rows = $this->queryFetchAll($sql);

        $result = [];
        foreach ($rows as $row) {
            $name = $row['COLUMN_NAME'];
            $result[$name] = $row;
        }

        return $result;
    }
788526
public function findTableInArray($tablename) {
        foreach ($this->tables as $i => $table) {
            if ($tablename == $table->getName()) {
                return $i;
            }
        }
        return null;
    }
1192346
protected function getForeignKeys($tableName)
    {
        $foreignKeys = [];
        $rows = $this->fetchAll(sprintf(
            "SELECT
              CONSTRAINT_NAME,
              TABLE_NAME,
              COLUMN_NAME,
              REFERENCED_TABLE_NAME,
              REFERENCED_COLUMN_NAME
            FROM information_schema.KEY_COLUMN_USAGE
            WHERE REFERENCED_TABLE_SCHEMA = DATABASE()
              AND REFERENCED_TABLE_NAME IS NOT NULL
              AND TABLE_NAME = '%s'
            ORDER BY POSITION_IN_UNIQUE_CONSTRAINT",
            $tableName
        ));
        foreach ($rows as $row) {
            $foreignKeys[$row['CONSTRAINT_NAME']]['table'] = $row['TABLE_NAME'];
            $foreignKeys[$row['CONSTRAINT_NAME']]['columns'][] = $row['COLUMN_NAME'];
            $foreignKeys[$row['CONSTRAINT_NAME']]['referenced_table'] = $row['REFERENCED_TABLE_NAME'];
            $foreignKeys[$row['CONSTRAINT_NAME']]['referenced_columns'][] = $row['REFERENCED_COLUMN_NAME'];
        }

        return $foreignKeys;
    }
1229039
public function getColumnName($fieldName)
    {
        return isset($this->columnNames[$fieldName]) ?
                $this->columnNames[$fieldName] : $fieldName;
    }
1190549
public function listTableDetails($tableName)
    {
        $columns     = $this->listTableColumns($tableName);
        $foreignKeys = [];
        if ($this->_platform->supportsForeignKeyConstraints()) {
            $foreignKeys = $this->listTableForeignKeys($tableName);
        }
        $indexes = $this->listTableIndexes($tableName);

        return new Table($tableName, $columns, $indexes, $foreignKeys);
    }
977608
private function getTableColumnTypes($tableName)
    {
        $columnTypes = array();
        $columns = $this->dbHandler->query(
            $this->typeAdapter->show_columns($tableName)
        );
        $columns->setFetchMode(PDO::FETCH_ASSOC);

        foreach ($columns as $key => $col) {
            $types = $this->typeAdapter->parseColumnType($col);
            $columnTypes[$col['Field']] = array(
                'is_numeric'=> $types['is_numeric'],
                'is_blob' => $types['is_blob'],
                'type' => $types['type'],
                'type_sql' => $col['Type'],
                'is_virtual' => $types['is_virtual']
            );
        }

        return $columnTypes;
    }
1003042
public static function getTableIndices( $tableName, $refresh = false )
	{
		static $data = [];
		
		if( isset( $data['$tableName'] ) ) {
			return $data['$tableName'];
		}
		
		$indexes = \Yii::$app->db->schema->getTableIndexes( $tableName, $refresh );
		
		foreach( $indexes as $index ) {
			$data[ $tableName ][ $index->name ] = $index;
		}
		
		return $data;
	}
579966
public function getTableCreateSql($tableName)
    {
        $sql = sprintf('SHOW CREATE TABLE %s', $this->ident($tableName));
        $result = $this->pdo->query($sql)->fetch();

        return $result['CREATE TABLE'];
    }
827954
public function getIndexes($tableName)
    {
        $indexes = [];
        $sql = "SELECT I.[name] AS [index_name], I.[index_id] as [index_id], T.[object_id] as [table_id]
FROM sys.[tables] AS T
  INNER JOIN sys.[indexes] I ON T.[object_id] = I.[object_id]
WHERE T.[is_ms_shipped] = 0 AND I.[type_desc] <> 'HEAP'  AND T.[name] = '{$tableName}'
ORDER BY T.[name], I.[index_id];";

        $rows = $this->fetchAll($sql);
        foreach ($rows as $row) {
            $columns = $this->getIndexColums($row['table_id'], $row['index_id']);
            $indexes[$row['index_name']] = ['columns' => $columns];
        }

        return $indexes;
    }
1369212
public function getFields($tableName) {
        list($tableName) = explode(' ', $tableName);
        $result = $this->query("select a.column_name,data_type,decode(nullable,'Y',0,1) notnull,data_default,decode(a.column_name,b.column_name,1,0) pk "
                  ."from user_tab_columns a,(select column_name from user_constraints c,user_cons_columns col "
          ."where c.constraint_name=col.constraint_name and c.constraint_type='P'and c.table_name='".strtoupper($tableName)
          ."') b where table_name='".strtoupper($tableName)."' and a.column_name=b.column_name(+)");
        $info   =   array();
        if($result) {
            foreach ($result as $key => $val) {
                $info[strtolower($val['column_name'])] = array(
                    'name'    => strtolower($val['column_name']),
                    'type'    => strtolower($val['data_type']),
                    'notnull' => $val['notnull'],
                    'default' => $val['data_default'],
                    'primary' => $val['pk'],
                    'autoinc' => $val['pk'],
                );
            }
        }
        return $info;
    }
147645
protected function getIndexes($tableName)
    {
        $indexes = [];
        $rows = $this->fetchAll(sprintf('pragma index_list(%s)', $tableName));

        foreach ($rows as $row) {
            $indexData = $this->fetchAll(sprintf('pragma index_info(%s)', $row['name']));
            if (!isset($indexes[$tableName])) {
                $indexes[$tableName] = ['index' => $row['name'], 'columns' => []];
            }
            foreach ($indexData as $indexItem) {
                $indexes[$tableName]['columns'][] = strtolower($indexItem['name']);
            }
        }

        return $indexes;
    }
301840
public function getTableColumnList($tableName) {

        if (!array_key_exists($tableName, $this->tableList)) {

            $this->addColumnMap($tableName, $this->getColumnMappingsFromConfig($tableName));
        }

        return $this->tableList[$tableName];
    }
872427
public function getIndexes($columnName = null) {
        if (!$this->indexes) {
            $this->indexes = array();
        }
        return ($columnName) ? $this->indexes[$columnName] : $this->indexes;
    }
772348
protected function _getColumns($tableName)
    {

        $params = [
            ':schemaName' => $this->_adapter->getSchemaName(),
            ':tableName' => $tableName
        ];
        return $this->_adapter->query($this->_getColumnsSql, $params);
    }