将我的代码从mysql转换为SQL服务器(SQLsrv),但是在此处使用mysql_field_name时遇到问题:
foreach($this->aCols as $i=>$col)
{
if($col['c']=='')
{
if(is_string($col['f']))
$this->aCols[$i]['c']=ucfirst($col['f']);
else
$this->aCols[$i]['c']=ucfirst(mysql_field_name($res,$col['f']));
}
}
答案 0 :(得分:1)
我认为这将是sqlsrv_get_field()
。有关文档和代码示例,请参阅以下MSDN文档(链接):
语法:
sqlsrv_get_field( resource $stmt, int $fieldIndex)
取自MSDN(样本用法):
$tsql = "SELECT ReviewerName, Comments
FROM Production.ProductReview
WHERE ProductReviewID=1";
$stmt = sqlsrv_query( $conn, $tsql);
if( $stmt === false )
{
echo "Error in statement preparation/execution.\n";
die( print_r( sqlsrv_errors(), true));
}
/* Make the first row of the result set available for reading. */
if( sqlsrv_fetch( $stmt ) === false )
{
echo "Error in retrieving row.\n";
die( print_r( sqlsrv_errors(), true));
}
$name = sqlsrv_get_field( $stmt, 0);
echo "$name: ";