Solved

get all the column names of a table

Posted on 2014-03-22
3
267 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 109

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Moving from Mcrypt to OpenSSL 18 47
Wordpress Security 29 49
removing a class in javascript 4 50
Uploading a CSV Data Import via PHP & MySql 3 34
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

830 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