mssql_close

(PHP 3, PHP 4, PHP 5)

mssql_close -- Close MS SQL Server connection

Description

bool mssql_close ( [resource link_identifier] )

mssql_close() closes the link to a MS SQL Server database that's associated with the specified link identifier. If the link identifier isn't specified, the last opened link is assumed.

如果成功则返回 TRUE,失败则返回 FALSE

Note that this isn't usually necessary, as non-persistent open links are automatically closed at the end of the script's execution.

mssql_close() will not close persistent links generated by mssql_pconnect().

See also mssql_connect(), and mssql_pconnect().


add a note add a note User Contributed Notes
szklarzewicz (at) wp (dot) pl
14-Oct-2005 01:48
Please note that on PHP5 this function dont work correct. You have to call it at last two times to make it work.

example:
<?PHP
$query
= mssql_query('SELECT * FROM T1'); // query error, T1 object invand
$query = mssql_fetch_row($query);
print_r($query);

mssql_select_db('DB1', $conn); //db dont exists error

$conn=@mssql_connect('localhost','usr','psw'); //conn success
mssql_select_db('DB1', $conn); //no errors

$query = mssql_query('SELECT * FROM T1'); // no problem, query success
$query = mssql_fetch_row($query);
print_r($query);  // success

echo '<hr>';

mssql_close() or die('failed closing mssql'); // no error!
mssql_select_db('DB2', $conn); //no errors!

$query = mssql_query('SELECT * FROM T2'); // no problem, query success
$query = mssql_fetch_row($query);
print_r($query);  // success

mssql_close() or die('failed closing mssql'); // no error, mssql closed
mssql_select_db('DB2', $conn); //failed, db dont exists

$query = mssql_query('SELECT * FROM T2'); // query error, T2 object invand
$query = mssql_fetch_row($query);
print_r($query);  // failed
?>

so, in fact you have to call mssql_close() two times to shutdown connection..