0

Is there an easy way to "SELECT * FROM TABLE" , but also include the column names in the first row?

Many thanks in advance

Amien
  • 954
  • 2
  • 11
  • 18

1 Answers1

1

MySQL does not deliver the column names as a row, but it certanly does deliver them. You can set the connection type to associative (instead of indexed) to get results like 'id' => 123 instead of [0] => 123.

Since every result set (row) contains the names as array keys, you can get them with array_keys($row) (PHP-syntax, others alike). This is the most common procedure to build e.g. CSV files.

Zsolt Szilagyi
  • 4,741
  • 4
  • 28
  • 44