Jump to content

Pre MySQL 5 Column Name Retrieval for Use in Queries


fenway

Recommended Posts

I doubt there is a solution to this problem, but I figured I'd share my frustrations.  I know you can run SHOW COLUMNS to get the details of each column in a table, but for some reason, this is "output-only", and can't be used as a proper result set -- and I don't know why.  AFAIK, there is no workaround to being able to "extract" such a list of fields in any way.

If anyone has a brilliant workaround, I'd be duly impressed.
Link to comment
Share on other sites

show columns do return a resultset
[code]
<?php
    $sql = "show columns from city";
    $rs = mysql_query($sql);
   
    while ($values = mysql_fetch_assoc($rs))
    {
        print_r($values);
    }
?>
[/code]

output:
[code]
Array
(
    [Field] => idn
    [Type] => int(10) unsigned
    [Null] => NO
    [Key] => PRI
    [Default] =>
    [Extra] => auto_increment
)
Array
(
    [Field] => name
    [Type] => varchar(45)
    [Null] => NO
    [Key] =>
    [Default] =>
    [Extra] =>
)
Array
(
    [Field] => state
    [Type] => varchar(45)
    [Null] => NO
    [Key] =>
    [Default] =>
    [Extra] =>
)
Array
(
    [Field] => path
    [Type] => varchar(128)
    [Null] => NO
    [Key] =>
    [Default] =>
    [Extra] =>
)
Array
(
    [Field] => link
    [Type] => varchar(128)
    [Null] => NO
    [Key] =>
    [Default] =>
    [Extra] =>
)
[/code]
is that what you wanted? it seems to work fine on my machine.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.