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.
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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.