Solved

get all the column names of a table

Posted on 2014-03-22
3
259 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
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 108

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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

707 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now