public function getColumnNames(string $table, bool $withTableName = false, bool $aliased = false)
    {
        $cols = [];

        if ($this->databaseType === 'mysql') {
            $sql = "SHOW COLUMNS FROM {$table}";
            $tableNameIndex = 'Field';
        } elseif ($this->databaseType === 'sqlite') {
            $sql = "PRAGMA table_info({$table})";
            $tableNameIndex = 'name';
        } else {
            throw new \RuntimeException("Unsupported database type: '{$this->databaseType}'");
        }

        # Get all columns from a selected table
        $r = $this->query($sql)->fetchAll();
        $this->logQuery($sql);

        # Add column names to $cols array
        foreach ($r as $i => $col) {
            $colName = $col[$tableNameIndex];

            if ($aliased) {
                $i = "{$table}_{$colName}";
            }

            if ($withTableName) {
                $colName = "{$table}.${colName}";
            }

            $cols[$i] = $colName;
        }

        return $cols;
    }
public function getColumnNames(string $table, bool $withTableName = false, bool $aliased = false)
    {
        $cols = [];

        if ($this->databaseType === 'mysql') {
            $sql = "SHOW COLUMNS FROM {$table}";
            $tableNameIndex = 'Field';
        } elseif ($this->databaseType === 'sqlite') {
            $sql = "PRAGMA table_info({$table})";
            $tableNameIndex = 'name';
        } else {
            throw new \RuntimeException("Unsupported database type: '{$this->databaseType}'");
        }

        # Get all columns from a selected table
        $r = $this->query($sql)->fetchAll();
        $this->logQuery($sql);

        # Add column names to $cols array
        foreach ($r as $i => $col) {
            $colName = $col[$tableNameIndex];

            if ($aliased) {
                $i = "{$table}_{$colName}";
            }

            if ($withTableName) {
                $colName = "{$table}.${colName}";
            }

            $cols[$i] = $colName;
        }

        return $cols;
    }
public function getColumnNames ( string $ table , bool $ withTableName = false , bool $ aliased = false ) { $ cols = [ ] ; if ( $ this -> databaseType === 'mysql' ) { $ sql = "SHOW COLUMNS FROM {$table}" ; $ tableNameIndex = 'Field' ; } elseif ( $ this -> databaseType === 'sqlite' ) { $ sql = "PRAGMA table_info({$table})" ; $ tableNameIndex = 'name' ; } else { throw new \ RuntimeException ( "Unsupported database type: '{$this->databaseType}'" ) ; } # Get all columns from a selected table $ r = $ this -> query ( $ sql ) -> fetchAll ( ) ; $ this -> logQuery ( $ sql ) ; # Add column names to $cols array foreach ( $ r as $ i => $ col ) { $ colName = $ col [ $ tableNameIndex ] ; if ( $ aliased ) { $ i = "{$table}_{$colName}" ; } if ( $ withTableName ) { $ colName = "{$table}.${colName}" ; } $ cols [ $ i ] = $ colName ; } return $ cols ; }
Get a list of the table fields.

@param string $table Table name
@param bool $withTableName Add the table name to the column names
@param bool $aliased Use an alias as key in the returned array
@return array List of the table fields
Get a list of the table fields .