专业网站建设品牌,十四年专业建站经验,服务6000+客户--广州京杭网络
免费热线:400-683-0016      微信咨询  |  联系我们

sqlsrv_num_fields

当前位置:网站建设 > 技术支持
资料来源:网络整理       时间:2023/2/14 0:06:09       共计:3628 浏览

检索活动结果集中的字段数。请注意,可以在执行任何预定义语句之前或之后对其调用 sqlsrv_num_fields

语法

sqlsrv_num_fields( resource $stmt)

参数

$stmt:目标结果集在其上处于活动状态的语句。

返回值

表示活动结果集中的字段数的整数值。如果发生错误,则返回布尔值 false

示例

以下示例执行查询以检索 Adventureworks 数据库的 HumanResources.Department 表中前三行的所有字段。sqlsrv_num_fields 函数确定相应结果集中的字段数。这样可以通过循环访问每个返回行中的字段来显示数据。

此示例假定本地计算机上已安装 SQL Server 和 AdventureWorks 数据库。从命令行运行此示例时,所有的输出都将写入控制台。

<?php
/* Connect to the local server using Windows Authentication and 
specify the AdventureWorks database as the database in use. */
$serverName = "(local)";
$connectionInfo = array( "Database"=>"AdventureWorks");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn === false )
{
     echo "Could not connect.\n";
     die( print_r( sqlsrv_errors(), true));
}

/* Define and execute the query. */
$tsql = "SELECT TOP (3) * FROM HumanResources.Department";
$stmt = sqlsrv_query($conn, $tsql);
if( $stmt === false)
{
     echo "Error in executing query.\n";
     die( print_r( sqlsrv_errors(), true));
}

/* Retrieve the number of fields. */
$numFields = sqlsrv_num_fields( $stmt );

/* Iterate through each row of the result set. */
while( sqlsrv_fetch( $stmt ))
{
     /* Iterate through the fields of each row. */
     for($i = 0; $i < $numFields; $i++)
     {
          echo sqlsrv_get_field($stmt, $i, 
                   SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR))." ";
     }
     echo "\n";
}

/* Free statement and connection resources. */
sqlsrv_free_stmt( $stmt );
sqlsrv_close( $conn );
?>

另请参见

参考

sqlsrv_field_metadata

概念

关于文档中的代码示例

其他资源

API 参考 (SQL Server Driver for PHP)
版权说明:
本网站凡注明“广州京杭 原创”的皆为本站原创文章,如需转载请注明出处!
本网转载皆注明出处,遵循行业规范,如发现作品内容版权或其它问题的,请与我们联系处理!
欢迎扫描右侧微信二维码与我们联系。
·上一条:sqlsrv_prepare | ·下一条:sqlsrv_num_rows

Copyright © 广州京杭网络科技有限公司 2005-2025 版权所有    粤ICP备16019765号 

广州京杭网络科技有限公司 版权所有