I'm not sure if there's a common command syntax among db servers to do this, but here's how you do it with MySQL:
$link = mysql_connect("localhost", "mysql_user", "mysql_password")
or die("Could not connect");
$fields = mysql_list_fields("database_name", "table_name", $link);
$columns = mysql_num_fields($fields);