Re: Getting only the column names

From: Gordon Burditt <gordonb.tydf1_at_burditt.org>
Date: Fri, 29 Jul 2016 21:24:57 -0500
Message-ID: <7Zidnc7Z8pVkkgHKnZ2dnUU7-efNnZ2d_at_posted.internetamerica>


> Good point. I don't use this table because it's non-standard and not
> guaranteed to remain the same format. But if the OP is just dealing
> with a limited number of versions of MySQL, this will work.

Depending on the query, I've run into some situations just poking around the information_schema database where queries ran really, really slow. It didn't seem to be a problem for just getting column names.

> But I also never found it hard to parse DESCRIBE TABLE (a pretty simple
> REGEX, even for me :) ), and it is portable across most databases.

Another way to do it: if you can control the query, the C and PHP APIs at least return metadata along with the query, giving the same column names as the "mysql" command-line utility. The call mysql_fetch_field() can be used in the C API and mysqli_result::fetch_fields in the PHP ("mysqli") interface. This can be "fooled" by using "AS" in the query. Other things appear if the data came from a function or expression.

[Quoted] Also, using the PHP function mysql_fetch_assoc, it will put the column names as the keys in an array. You are free to use these names and ignore the associated data.

I am not familiar with other MySQL APIs such as Java, Python, Ruby, etc. but they probably include the same information in some form.

Yes, the MySQL API calls are probably MySQL-specific. Received on Sat Jul 30 2016 - 04:24:57 CEST

Original text of this message