Goty Metal
Goty Metal

Reputation: 336

SQL - Show column names from a sql result

Something similar has been asked before but not answered and it's not 100% the same, what i have is an SQL like:

SELECT * FROM table1 JOIN table2;

I know that I can get the columns of a table using DESC, DESCRIBE or SHOW BUT, that function doesn't allow multiple tables neither SQL queries.

Upvotes: 1

Views: 114

Answers (1)

Darwin von Corax
Darwin von Corax

Reputation: 5256

Both mysqli::fetch_assoc() and PDOStatement::fetch() can return a row as an associative array, which means that the columns are indexed by column name rather than by number. You can then use the array_keys() function to extract a list of the column names, in order, from the row.

Upvotes: 2

Related Questions