That returns a simple array of the column names / variable names in your table or array as strings, which is what I needed to dynamically build MySQL queries. My frustration was that I simply don't know how to index arrays in PHP very well, so I wasn't sure what to do with the results from DESC or SHOW. Hope my answer is helpful to beginners like myself!
if you use php, use this gist.
it can get select fields full info with no result,and all custom fields such as:
if above sql return no data,will also get the field names aname, bname, b's other field name
just two line:
Edit: Today I learned the better way of doing this. Please see ircmaxell's answer.
Parse the output of
SHOW COLUMNS FROM table;
Here's more about it here: http://dev.mysql.com/doc/refman/5.0/en/show-columns.html
Not sure if this is what you were looking for, but this worked for me:
That returns a simple array of the column names / variable names in your table or array as strings, which is what I needed to dynamically build MySQL queries. My frustration was that I simply don't know how to index arrays in PHP very well, so I wasn't sure what to do with the results from DESC or SHOW. Hope my answer is helpful to beginners like myself!
To check result:
print_r($col_names);
This query fetches a list of all columns in a database without having to specify a table name. It returns a list of only column names:
However, when I ran this query in phpmyadmin, it displayed a series of errors. Nonetheless, it worked. So use it with caution.
Use
mysql_fetch_field()
to view all column data. See manual."Warning This extension is deprecated as of PHP 5.5.0, and will be removed in the future."