Solved

get all the column names of a table

Posted on 2014-03-22
3
268 Views
Last Modified: 2014-03-22
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
Comment
Question by:M. Jayme Nagy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 58

Assisted Solution

by:Gary
Gary earned 250 total points
ID: 39947679
If you mean the table column names then just run as an sql

DESCRIBE table_name
0
 
LVL 110

Accepted Solution

by:
Ray Paseur earned 250 total points
ID: 39947715
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
 
LVL 6

Author Closing Comment

by:M. Jayme Nagy
ID: 39947747
thanks guys
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

739 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question