Solved

get all the column names of a table

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

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…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

776 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