tags:

views:

153

answers:

3

How to get column name in SQL Server,

and also how to execute that query in php ,

+1  A: 

Here is how you can do that

$result = mysql_query("DESCRIBE TABLE table");
$data = mysql_fetch_assoc($result);
print_r($data);
Pierre 303
he asked about mssql not mysql
Yorirou
Sorry to have frustrated you.
Pierre 303
+3  A: 

1.Get column name in mssql 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);

can you try like this ?

AdalArasan
A: 

/* ** 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: ' . mysql_error()); // Get result count: $Count = mssql_num_rows($result); print "Showing $count rows:


\n\n"; // Fetch rows: while ($Row = mssql_fetch_assoc($result)) {

print $Row['Fieldname'] . "\n";   }   mssql_close($con);

my problem fixed..

Bharanikumar
And we had absolutely no idea what problem you had. Oh well, I assume you know what you're talking about.
BoltClock