A more portable way would be the following (I am using PEAR::DB, but you could
use the native driver as long as it returns an Associative Array.:

include 'db.php';
$db = DB::connect($dsn);
$strSQL = "SELECT * FROM {Table}";
$row = $db->getRow($strSQL, DB_FETCHMODE_ASSOC);

$field_names = array_keys($row);

Iterate $field_names for the field names from the table.  This should work for
any database that PHP can use.

Have fun...
-- 
Scott Carr
OpenOffice.org
Documentation Maintainer
http://documentation.openoffice.org/


Quoting David Hollister <[EMAIL PROTECTED]>:

> Database jargon can always be a factor in clear communication, so I'll be
> careful in my suggestions.  I take your question to mean: "how do I return
> the column names from any given table within MS SQL?"  If that's what you
> want, you need to select information from the [syscolumns] table in your
> database context.  Example: " select * from [syscolumns] where id =
> 693577509 ".  I collected the table id 693577509 from [sysobjects], which
> keeps a record of table name and system id for that table.  This gives me
> the column names for everything in that table.  
> 
> Does that answer your question or are you looking for something else?  
> 
> Dave
> 
> -----Original Message-----
> From: R.S. Herhuth [mailto:[EMAIL PROTECTED]]
> Sent: Friday, August 16, 2002 2:07 AM
> To: [EMAIL PROTECTED]
> Subject: [PHP-WIN] Getting Field Names in Microsoft SQL
> 
> 
> I'm trying to build a dynamic script that basically extracts all of the
> fields in a MS SQL database...I just can't seem to figure out how to get
> at the field names themselves.  I am using the mssql_fetch_array
> followed by the $row['field_name'] in an array.  But I would like to
> make the field_name dynamic (i.e. not knowing the field_names ahead of
> time) which would make the script adaptable to any table in the
> database.  So if I get the field's value by $row['field_name'] how do I
> get at the field's name?
> 
> thanks,
> Ron
> 
> --
> PHP Windows Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> -- 
> PHP Windows Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 
> 


-------------------------------------------------
This mail sent through IMP: http://horde.org/imp/

-- 
PHP Windows Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to