关闭指定的连接并释放相关资源。
sqlsrv_close( resource $conn )
$conn:要关闭的连接。
若非使用无效参数调用此函数,则为布尔值 true。如果使用无效参数调用此函数,则返回 false。
注意: |
---|
Null 是此函数的有效参数。使用此参数,可在脚本中多次调用此函数。例如,如果在一个错误条件中关闭某一连接并在脚本末尾再次关闭该连接,则对 sqlsrv_close 的第二次调用将返回 true,因为对 sqlsrv_close 的第一次调用(在错误条件中)将相应连接资源设置为 null。
|
下面的示例将关闭一个连接。此示例假定在本地计算机上已安装 SQL Server。从命令行运行此示例时,所有的输出都将写入控制台。
<?php /*Connect to the local server using Windows Authentication and specify the AdventureWorks database as the database in use. */ $serverName = "(local)"; $conn = sqlsrv_connect( $serverName); if( $conn === false ) { echo "Could not connect.\n"; die( print_r( sqlsrv_errors(), true)); } //----------------------------------------------- // Perform operations with connection here. //----------------------------------------------- /* Close the connection. */ sqlsrv_close( $conn); echo "Connection closed.\n"; ?>
Copyright © 广州京杭网络科技有限公司 2005-2025 版权所有 粤ICP备16019765号
广州京杭网络科技有限公司 版权所有