Hello,
I'm trying to create a page with a list of column names from a SQL table. The query works in SQL but not in PHP... can anyone offer some help?
I'm trying to create a page with a list of column names from a SQL table. The query works in SQL but not in PHP... can anyone offer some help?
Code:
<html>
<body>
Testing
<?PHP
$connectionInfo = array("UID" => "me_myslef", "PWD" => "my_password", "Database"=>"my_db","ReturnDatesAsStrings" => true);
$db = sqlsrv_connect("my_server",$connectionInfo) or die("Unable to connect to server");
$result = sqlsrv_query($db,"SELECT
[Column Name] = c.name,
[Description] = ex.value
FROM
sys.columns c
LEFT OUTER JOIN
sys.extended_properties ex
ON
ex.major_id = c.object_id
AND ex.minor_id = c.column_id
AND ex.name = 'MS_Description'
WHERE
OBJECTPROPERTY(c.object_id, 'IsMsShipped')=0
AND OBJECT_NAME(c.object_id) = 'DailyTotals'
ORDER
BY OBJECT_NAME(c.object_id), c.column_id");
while ($row = sqlsrv_fetch_array($result)){
echo $row['Column Name'];
}
?>
</body>
</html>