|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2005-09-04 23:43 UTC] qlogix at gmail dot com
Description:
------------
mssql_query() does not use the link identifier your specify. If you open two database connections using mssql_connect then specify which one of those connections to use in mssql_query(), the mssql_query() function will just use the last connection opened, no matter what.
CONN1 is the address to my local mssql server.
Table donations exists in database db1, not in db2
Table tbl_admin_user exists in database db2, not in db1
If I switch the order of connections, the first query works and the second one fails, and of course vice versa.
In my case, yes, I am opening two connections to the same server, just changing the name of the database I want to use, however this application can be configured to connect to to different servers.
Reproduce code:
---------------
$conn1 = mssql_connect("CONN1","dbuser","dbpass");
mssql_select_db("db1",$conn1);
$conn2 = mssql_connect("CONN1","dbuser","dbpass");
mssql_select_db("db2",$conn2);
$sq = mssql_query("SELECT * FROM donations",$conn1);
$sq2 = mssql_query("SELECT * FROM tbl_admin_user",$conn2);
Expected result:
----------------
No errors.
Actual result:
--------------
Warning: mssql_query(): message: Invalid object name 'donations'. (severity 16) in C:\htdocs\noname2.php on line 8
Warning: mssql_query(): Query failed in C:\htdocs\noname2.php on line 8
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 18:00:01 2025 UTC |
If the same host, usr and password is used for both connections the driver will not create a new connection. To get arround this problem you need to create two aliases for the SQL Server host name like this: $conn1 = mssql_connect("CONN1","dbuser","dbpass"); mssql_select_db("db1",$conn1); $conn2 = mssql_connect("CONN2","dbuser","dbpass"); mssql_select_db("db2",$conn2); The two host names should point to the same server, but it forces the extension to create a new connection each time.