php.net |  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
Votes:1
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
 [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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-09-04 23:56 UTC] sniper@php.net
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] fmk@php.net
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.
 [2005-09-05 07:13 UTC] fmk@php.net
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
http://snaps.php.net/.
 
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 Mar 19 07:01:29 2024 UTC