How do I convert a mssql_field_name function to sqlsrv
Posted: Fri Nov 11, 2016 2:59 am
Hi,
I am converting the mssql functions in my application to sqlsrv functions as part of a migration activity from SQL Server 2003 to SQL Server 2008. I am not getting the expected results when I just replace mssql_field_name with its equivalent in sqlsrv i.e sqlsrv_field_metadata. I am not sure if I am using the right sqlsrv function for this. Could anyone help me here. The code which I am trying to convert looks something like this:
I am converting the mssql functions in my application to sqlsrv functions as part of a migration activity from SQL Server 2003 to SQL Server 2008. I am not getting the expected results when I just replace mssql_field_name with its equivalent in sqlsrv i.e sqlsrv_field_metadata. I am not sure if I am using the right sqlsrv function for this. Could anyone help me here. The code which I am trying to convert looks something like this:
Code: Select all
<?php
$result = mssql_query($query, $conn);
$rows = mssql_num_rows($result);
$cols = mssql_num_fields($result);
if(rows>0)
{
for($i= 0;$i<$cols;++$i)
{
$colname = mssql_field_name($result,$i);
echo " <th>$colname</th>";
}
echo "</tr>";
}
if($rows<=0){
echo "No Results found for the specified inputs";
exit();
}else
{
for($i = 0;$i < $rows; $i++)
{
echo "<tr>";
for($j =0;$j < $cols; $j++)
{
$colname = mssql_field_name($result,$j);
$out = mssql_result($result,$i,"$colname");
echo "<td> $out </td>";
}
echo "</tr>";
}
echo "<br>";
}
?>