Subject: | Showing table columns |
DBD::mysqlPP 0.04
Net::MySQL 0.08
perl v5.8.3 built for i486-linux
Linux snoopy 2.6.4 #3 Sun Mar 28 23:02:49 BST 2004 i686 unknown
I'm trying to run the following SQL:
DESCRIBE <tablename>
using the following perl code:
eval{$dbh = DBI -> connect("DBI:mysqlPP:database=$database;host=$host", $user, $password, {'RaiseError' => 1});};
if(!$@){
my $query = $dbh -> prepare("DESCRIBE user;");
eval{$query -> execute();};
if(!$@){
my $names = $query ->{'NAME'}; #all returned field names
for(my $i = 0; $i < $query ->{'NUM_OF_FIELDS'}; $i++){print "<th>$$names[$i]</th>";} #get field names
print "</tr>\n"; #finished field names
while(my @fields = $query -> fetchrow_array()){
print "<tr bgcolor=\"#FFFFFF\">";
foreach(@fields){
if($_){ #this field has a value
print "<td>$_</td>";
}
else{print "<td> </td>";} #this field has a null value
}
print "</tr>\n";
}
print "<tr><td align=\"center\" colspan=\"" . $query ->{'NUM_OF_FIELDS'} . "\">" . $query -> rows() . "Rows found</td></tr>\n"; #print rows found
$query -> finish();
}
else{$error = "Problem with query: " . $dbh -> errstr;}
$dbh -> disconnect();
}
else{$error = "Cant connect to MySQL server: " . $@;}
It seems to return all the rows in one row with lots of binary escape characters for newlines etc.
I have also tried SHOW COLUMNS FROM <tablename>; but with the same problem