如何在SQL Server中获取列名? [关闭]

How to get a column name in SQL Server?

And also, how to execute that query in PHP?

1. Get column name in SQL Server

For example:

SELECT table_name=sysobjects.name,
       column_name=syscolumns.name,
       datatype=systypes.name,
       length=syscolumns.length
FROM sysobjects

2. Example to execute the query in PHP

$firstname = 'fred';
$lastname  = 'fox';

$query = sprintf("SELECT firstname, lastname FROM friends WHERE firstname='%s' AND lastname='%s'",
    mysql_real_escape_string($firstname),
    mysql_real_escape_string($lastname));

$result = mysql_query($query);

Here is how you can do that

$result = mysql_query("DESCRIBE TABLE table");
$data = mysql_fetch_assoc($result);
print_r($data);

My problem was fixed with the following code.

/*
** Connect to database:
*/   // Connect to the database (host, username, password) $con =
mssql_connect('localhost','admin','foo')
    or die('Could not connect to the server!'); // Select a database:

mssql_select_db('Northwind')
    or die('Could not select a database.'); // Example query: (TOP 10 equal LIMIT 0,10 in MySQL)
$SQL =
    "SELECT TOP 10 * FROM ExampleTable
     ORDER BY ID ASC";

// Execute query:
$result = mssql_query($SQL)
    or die('A error occured: ' . mssql_error()); // Get result count:
$Count = mssql_num_rows($result);
print "Showing $count rows:<hr/>

";
// Fetch rows: while ($Row =
mssql_fetch_assoc($result)) {
    print $Row['Fieldname'] . "
";
}
mssql_close($con);