Returning the field names from a database

Discussion in 'PHP' started by red_fiesta, Aug 4, 2008.

  1. #1
    Hi,

    I would like to return the field names from the database as well as the results...

    how do return fields names? i.e. what is the syntax?

    I am connecting to a mssql database using ADODB_FETCH_ASSOC

    Thanks
     
    red_fiesta, Aug 4, 2008 IP
  2. rohan_shenoy

    rohan_shenoy Active Member

    Messages:
    441
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    60
    #2
    
    SHOW COLUMNS FROM table_name
    
    Code (SQL):
     
    rohan_shenoy, Aug 4, 2008 IP
  3. red_fiesta

    red_fiesta Peon

    Messages:
    125
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    This is a command for mysql not sql server..

    Sql Throws UP

    Msg 156, Level 15, State 1, Line 1
    Incorrect syntax near the keyword 'FROM'.
     
    red_fiesta, Aug 4, 2008 IP
  4. Social.Network

    Social.Network Member

    Messages:
    517
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    35
    #4
    select column_name from information_schema.columns where table_name = 'table'
     
    Social.Network, Aug 4, 2008 IP
  5. Hallent

    Hallent Peon

    Messages:
    65
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Are you looking for the query to return field names? From the way I understood the question you arent. If you are ignore the rest... Your query should return an array of variables the keys for those variables with ADODB_FETCH_ASSOC should be the field names

    for ($resultsArray as $key=>$value){
    echo "Field name: $key --- Value: $value";
    }
     
    Hallent, Aug 5, 2008 IP
  6. reubix90

    reubix90 Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    they should return automatically under the $variable format....
     
    reubix90, Aug 5, 2008 IP