[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 276
  • Last Modified:

get all the column names of a table

Hi,

im curious if there is a way to detect the column headers / titles of a table in a pdo statement. i know i could probably just fetch the first row and then strip the data in the columns and just use the columns as variables. However, im curious if there is similar method
0
J N
Asked:
J N
2 Solutions
 
GaryCommented:
If you mean the table column names then just run as an sql

DESCRIBE table_name
0
 
Ray PaseurCommented:
If you use the "first row" method what you will get are either the column names or the alias names used in the query.    To get the true names of the columns you can use this query:

$sql = "SHOW COLUMNS FROM $your_favorite_table_name";

You'll get one row back for each of the columns.  In the resulting array or object look for the "Field" elements.
0
 
J NUnicorn wranglerAuthor Commented:
thanks guys
0

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now