New here? Read Greetings Earthling!

Get Columns Set In MySQL Table With PHP

There are times when your code has to add/remove columns dynamically to/from a mysql table. And there are many other programming situations where you need to check if the field exists in a mysql table column list or just get the column set for further use.

There are several methods of doing this but I will cover just one right now: the easy one. This easy one does not rely on a mysql query but a fake query. The others I know are:

  1. DESCRIBE [SCHEMA.]TABLE (schema is optional) and will return a set of results with the table columns and information about each of them.
  2. A SELECT query against INFORMATION_SCHEMA.COLUMNS using TABLE_NAME and TABLE_SCHEMA requesting COLUMN_NAME.
    This method requires you to know the current selected database (SELECT DATABASE() LIMIT 1) which adds another query to the magic.

List A MySQL Table Column Set

Maybe there are other methods but this is my version of the magic and I do consider it the most simple.

Zone unavailable to unregistered users.
Registration is quick, painless and worth its weight in gold.

Basic ... huh? No data is returned but a set of columns returned by a resultsless query.

Category: MySQL, PHP

Comments are closed.