|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #34369 mssql_query() does not use link identifier
Submitted: 2005-09-04 23:43 UTC Modified: 2005-09-05 07:13 UTC
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: qlogix at gmail dot com Assigned: fmk (profile)
Status: Closed Package: Feature/Change Request
PHP Version: 6CVS, 5CVS, 4CVS (2005-09-05) OS: *
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: qlogix at gmail dot com
New email:
PHP Version: OS:


 [2005-09-04 23:43 UTC] qlogix at gmail dot com
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");

$conn2 = mssql_connect("CONN1","dbuser","dbpass");

$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


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2005-09-04 23:56 UTC]
This is not a bug, just missing feature. See mysql_connect() prototype: 

"resource mysql_connect ([string server [, string username [, string password [, bool new_link [, int client_flags]]]]])"

mssql_query() misses the 'new_link' parameter.

 [2005-09-05 00:28 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");

$conn2 = mssql_connect("CONN2","dbuser","dbpass");

The two host names should point to the same server, but it forces the extension to create a new connection each time.
 [2005-09-05 07:13 UTC]
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
Thank you for the report, and for helping us make PHP better.

A new parameter to mssql_connect makes it possible to force the creation of a new link.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Jul 16 16:01:27 2024 UTC