views:

146

answers:

1

I have an open SQL Server connection and need to open and close another while maintaining the first connection. I CANNOT hold onto the resource ID for the original.

  1. Connection A (may or may not be open)
  2. Open connection B
  3. Perform a few queries using connection B
  4. Close connection B
  5. Continue working with connection A
A: 

If you are using the below method to establish your connections you may not really have an 'A' and 'B' connection. It may also provide a way for you to recover the previously opened 'A' connection if you utilize the '$new_link' argument.

resource mssql_connect ([ string $servername [, string $username [, string $password [, bool $new_link ]]]] )

from php.net http://www.php.net/manual/en/function.mssql-connect.php

new_link
If a second call is made to mssql_connect() with the same arguments, no new link will be established, but instead, the link identifier of the already opened link will be returned. This parameter modifies this behavior and makes mssql_connect() always open a new link, even if mssql_connect() was called before with the same parameters.

So basically if you create connection A and then connection B with new_link true then use and close connection B, your next call to mssql_connect with new_link false would return connection A.

I have not tested this but the documentation shows it to be possible and though it is probably not ment to solve your problem you may be able to use it for that.

I am however curious why you can not hold onto A as well as why you need the second connection.

avirtuos
I looked at that, the problem is when I close "B" all connection is lost even with new link. I can't hold the resource id for "A" since it is poorly engrained code.
Davin
Are you sure 'B' is really different from 'A'. As i mentioned if you call mssql_connect more than once without setting new_link to true you just get the same link back so in that case closing 'B' would close 'A'.
avirtuos