mysql getting only column headers

liunx

Guest
Does anyone know the statement to get only the column headers from a table?

I've tried:
SHOW COLUMNS FROM test;
SHOW FIELDS FROM test;

It returns the other info about the columns with it.
I would like only the name field to be returned.

Here is an example of perl code I'm using:

my$dbh = DBI->connect($dbs) || &dberror("Couldn't connect to the database");
my$stm = "";
$stm = "SHOW COLUMNS FROM test;";
my$colheads = $dbh->prepare ($stm);
$colheads->execute() || &dberror("Couldn't do the statement \n$stm");
my$heads = "";
while (my @val = $colheads->fetchrow_array()){
$heads .= "<TABLE><tr>";
foreach(@val){
$heads .= "<td>$_</td>";
}
$heads .= "</tr></TABLE>";
}
print $heads;Please use the code bbTags! [ code ] [ /code ] (without the spaces).

How about this: my $dbh = DBI->connect($dbs) || &dberror("Couldn't connect to the database");
my $stm = "";
$stm = "SHOW COLUMNS FROM test;";
my $colheads = $dbh->prepare ($stm);
$colheads->execute() || &dberror("Couldn't do the statement \n$stm");
my $heads = "";

while (my @val = $colheads->fetchrow_array())
{
$heads .= "<TABLE><tr>";

foreach(@val)
{
$heads .= "<td>$_[0]</td>";
}
$heads .= "</tr></TABLE>";
}

print $heads;Each element of the array @val is an array itself, you require the first element of that array (which contains the column name).
 
Top