Results 1 to 14 of 14
  1. #1
    Join Date
    Jul 2004
    Posts
    14

    Unanswered: How to get column titles ?

    I would like to ask whether there is a way to get all columns ids (titles) of any table using sql commands in php ?

    Thanks

  2. #2
    Join Date
    Sep 2003
    Location
    The extremely Royal borough of Kensington, London
    Posts
    778
    Select column_name
    from all_tab_columns
    where table_name = 'tableA';
    Bessie Braddock: Winston, you are drunk!
    Churchill: And Madam, you are ugly. And tomorrow, I'll be sober, and you will still be ugly.

  3. #3
    Join Date
    Jul 2004
    Posts
    14
    Thanks for reply
    But this is not what i need to do :

    I put my question in another way :
    The only thing I have is the table name, and I want to get all its columns names.

  4. #4
    Join Date
    Sep 2003
    Location
    The extremely Royal borough of Kensington, London
    Posts
    778
    Allow me to clarify.

    Code:
    SQL> create table a
      2  (
      3  col1 number(2),
      4  col2 number(2),
      5  col3 number(2)
      6  );
    
    Table created.
    
    SQL> select column_name
      2  from all_tab_columns
      3  where table_name = 'A';
    
    COLUMN_NAME
    ------------------------------
    COL1
    COL2
    COL3
    Last edited by r123456; 07-19-04 at 09:24.
    Bessie Braddock: Winston, you are drunk!
    Churchill: And Madam, you are ugly. And tomorrow, I'll be sober, and you will still be ugly.

  5. #5
    Join Date
    Jul 2004
    Posts
    14
    THanks again
    But this command doesn't execute :
    My base is in a library called "revue" so for a normal request I type :

    $sql= 'select * from revue.My_table "
    $tab=executeSQL($sql)

    Where execute Sql is a function that return a table tht contains the sql result.

    To test your solution I typed :
    $sql= "select column_name
    from all_tab_columns
    where table_name = 'revue.user'";

    And it doesnt works : The error sais that "ALL_TAB_COLUMNS doesnt exists in revue"

    Thans for your patience

  6. #6
    Join Date
    Jul 2004
    Posts
    14
    Yes I see after you clarification
    But considering this, my command I put above should work no ?

  7. #7
    Join Date
    Sep 2003
    Location
    The extremely Royal borough of Kensington, London
    Posts
    778
    The solution I provided was for an Oracle database.

    SQL Server:

    Select column_name
    from information_schema.columns
    where table_name = 'tableA'
    Last edited by r123456; 07-19-04 at 09:39.
    Bessie Braddock: Winston, you are drunk!
    Churchill: And Madam, you are ugly. And tomorrow, I'll be sober, and you will still be ugly.

  8. #8
    Join Date
    Jul 2004
    Posts
    14
    I'm using ibm database ( on a pc AS400 ) ... it must have clasic SQLs (87 and 91 (or 93 dont remember) )
    Last edited by martones; 07-19-04 at 09:42.

  9. #9
    Join Date
    Sep 2003
    Location
    The extremely Royal borough of Kensington, London
    Posts
    778
    Try:

    describe table revue.My_table
    Bessie Braddock: Winston, you are drunk!
    Churchill: And Madam, you are ugly. And tomorrow, I'll be sober, and you will still be ugly.

  10. #10
    Join Date
    Jul 2004
    Posts
    14
    error : The syntax element REVUE isn't correct

  11. #11
    Join Date
    Sep 2003
    Location
    The extremely Royal borough of Kensington, London
    Posts
    778
    Bessie Braddock: Winston, you are drunk!
    Churchill: And Madam, you are ugly. And tomorrow, I'll be sober, and you will still be ugly.

  12. #12
    Join Date
    Jul 2004
    Posts
    14
    Thanks a lot again
    But I still get errors :[
    I tried : describe table revue.user
    describe select * from revue.user

    This gives errors

    : The syntax element "." isn't correct

    I execute this command with "odbc_do" php function

  13. #13
    Join Date
    Mar 2001
    Location
    Lexington, KY
    Posts
    606
    It's dirty but might work in a pinch:
    $sql= 'select * from revue.My_table where 1=0'
    $tab=executeSQL($sql)

    That way it would give an empty result set with the column info. Obviously the best solution is to find a way to get the schema of a table without running a query, but it might be harder in PHP since there is no result set object or anything to give you column information (you'll have to parse it yourself).
    Thanks,

    Matt

  14. #14
    Join Date
    Jul 2004
    Posts
    14
    Yes this would work as I stand alone sql command but not with php for the reason you said

    But thanks though Matt

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •