开发者

Open new SQL Server connection in PHP

开发者 https://www.devze.com 2022-12-20 18:47 出处:网络
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 开发者_StackOverflowthe original.

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 开发者_StackOverflowthe 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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消