Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

sqlsrv_close

SQL Server 2008 R2

Closes the specified connection and releases associated resources.


sqlsrv_close( resource $conn )

$conn: The connection to be closed.

The Boolean value true unless the function is called with an invalid parameter. If the function is called with an invalid parameter, false is returned.

Note Note

Null is a valid parameter for this function. This allows the function to be called multiple times in a script. For example, if you close a connection in an error condition and close it again at the end of the script, the second call to sqlsrv_close will return true because the first call to sqlsrv_close (in the error condition) sets the connection resource to null.

The following example closes a connection. The example assumes that SQL Server is installed on the local computer. All output is writing to the console when the example is run from the command line.

<?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";
?>
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.