V
V
VladRife2021-08-26 16:04:17
Laravel
VladRife, 2021-08-26 16:04:17

How to get columns in the order they appear in phpMyAdmin?

How to get columns in the order they appear in phpMyAdmin or other CRUD database system?
This is the order in which the columns appear in phpMyAdmin:
id | name | email | password | tables | personal

And this is how they come to me:
id | email | name | password | personal | tables

Source code:

public static function getColumns($table, $database): array
    {
        return (DB::table('information_schema.columns')
            ->select(['COLUMN_NAME', 'DATA_TYPE', 'COLUMN_KEY'])
            ->where('TABLE_NAME', $table)
            ->where('TABLE_SCHEMA', $database)
            ->orderByRaw("COLUMN_NAME <> 'id'")
            ->get()
            ->toArray());
    }


Maybe there is some way that can be solved within the framework of a Sql request, or a function in Laravel / PHP?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question