释放与指定语句关联的所有资源。在调用此函数后,将无法再次使用此语句。
sqlsrv_free_stmt( resource $stmt)
$stmt:要关闭的语句。
若非使用无效参数调用此函数,则为布尔值 true。如果使用无效参数调用此函数,则返回 false。
注意: |
---|
Null 是此函数的有效参数。使用此参数,可在脚本中多次调用此函数。例如,如果在错误条件下释放某语句并在脚本末尾再次释放此语句,则第二次调用 sqlsrv_free_stmt将返回 true,因为第一次调用 sqlsrv_free_stmt(在错误条件下)将相应的语句资源设置为 null。
|
以下示例创建语句资源,执行单个查询,并且调用 sqlsrv_free_stmt 以释放与语句关联的所有资源。此示例假定本地计算机上已安装了 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)); } $stmt = sqlsrv_query( $conn, "SELECT * FROM Person.Contact"); if( $stmt ) { echo "Statement executed.\n"; } else { echo "Query could not be executed.\n"; die( print_r( sqlsrv_errors(), true)); } /*------------------------------- Process query results here. -------------------------------*/ /* Free the statement and connection resources. */ sqlsrv_free_stmt( $stmt); sqlsrv_close( $conn); ?>
Copyright © 广州京杭网络科技有限公司 2005-2025 版权所有 粤ICP备16019765号
广州京杭网络科技有限公司 版权所有