From:             cdcr440 at hotmail dot com
Operating system: WinNT
PHP version:      4.3.1
PHP Bug Type:     MSSQL related
Bug description:  MSSQL: "Changed database context to" error when running query

Description:
------------
When selecting a database with mssql_select_db(), the error "Changed
database context to 'XXX'". DB server is MSSQL 2000.

The problem seems to be the result of running a query and the next time
the script tries to select the database, it fails with the above message,
which I wouldn't expect from mssql_query(). The failing query will first
run for a long time and fail with the above message. All subsequent
attempts to select the database will fail with the same message. But
running other queries in other scripts will be successful.

The behaviour of the bug is hard to predict and I haven't been able to
design a query that will surely generate the problem. Also the queries
that fail with PHP work fine in SQL Analyzer/Enterprise manager (connected
as the same user), so it's not a query/SQL problem.

The user I use to connect to the database has the target database as
default database therefore I wouldn't expect a change of context to be a
problem. Also the user can run exactly the same query with a very slightly
different value in one of the parameters and succeed(e.g. "hup" in the
query for VARCHAR will fail but "hu" for the same column will succeed), so
it's not an access right problem. However, the workaround I've found is to
use the sa user to connect to the server, which would tend to show that
it's a user problem.

I thought for a while that it was a problem with number of open
connections to the database, but I reduced them and the behaviour of the
bug isn't consistent with that as it can occur when very few concurrent
connections are open.

The bug also has been present in the last few versions of PHP, not only in
4.3.1.

I whish I could provide more useful information like a core dump, but the
failing code is very simple, I haven't figured out what the problem is,
and PHP doesn't crash.

Disclaimer: I searched for this bug in the bugs database, and found a
similar Sybase bug with the reporter didn't provide feedback. I didn't
find anything else. My sincere apologies if it has been reported before
and I missed it.



Reproduce code:
---------------
$this->dbID = MSSQL_CONNECT($this->theServer, $this->theUser,
$this->thePassword); // theServer etc are object variables
mssql_select_db($this->theDB, $this->dbID);

Running the query afterward is simply:
$this->theResults = mssql_query($this->theQuery, $this->dbID);  // where
$this->theQuery is the query string


The PHP log will simply contain:
[07-Jul-2003 17:40:43] PHP Warning:  mssql_select_db() [<a
href='http://www.php.net/function.mssql-select-db'>function.mssql-select-db</a>]:
Unable to select database:  XXX in myDB.class on line 57
[07-Jul-2003 17:40:43] PHP Warning:  mssql_query() [<a
href='http://www.php.net/function.mssql-query'>function.mssql-query</a>]:
Query failed in myDB.class on line 261


My php.ini options for MSSQL are as follows:
[MSSQL]
; Allow or prevent persistent links.
mssql.allow_persistent = On

; Maximum number of persistent links.  -1 means no limit.
mssql.max_persistent = -1

; Maximum number of links (persistent+non persistent).  -1 means no
limit.
mssql.max_links = -1

; Minimum error severity to display.
mssql.min_error_severity = 10

; Minimum message severity to display.
mssql.min_message_severity = 10

; Compatability mode with old versions of PHP 3.0.
mssql.compatability_mode = Off

; Valid range 0 - 2147483647.  Default = 4096.
mssql.textlimit = 10000000

; Valid range 0 - 2147483647.  Default = 4096.
mssql.textsize = 10000000

; Limits the number of records in each batch.  0 = all records in one
batch.
;mssql.batchsize = 15



-- 
Edit bug report at http://bugs.php.net/?id=24522&edit=1
-- 
Try a CVS snapshot (php4):  http://bugs.php.net/fix.php?id=24522&r=trysnapshot4
Try a CVS snapshot (php5):  http://bugs.php.net/fix.php?id=24522&r=trysnapshot5
Fixed in CVS:               http://bugs.php.net/fix.php?id=24522&r=fixedcvs
Fixed in release:           http://bugs.php.net/fix.php?id=24522&r=alreadyfixed
Need backtrace:             http://bugs.php.net/fix.php?id=24522&r=needtrace
Try newer version:          http://bugs.php.net/fix.php?id=24522&r=oldversion
Not developer issue:        http://bugs.php.net/fix.php?id=24522&r=support
Expected behavior:          http://bugs.php.net/fix.php?id=24522&r=notwrong
Not enough info:            http://bugs.php.net/fix.php?id=24522&r=notenoughinfo
Submitted twice:            http://bugs.php.net/fix.php?id=24522&r=submittedtwice
register_globals:           http://bugs.php.net/fix.php?id=24522&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=24522&r=php3
Daylight Savings:           http://bugs.php.net/fix.php?id=24522&r=dst
IIS Stability:              http://bugs.php.net/fix.php?id=24522&r=isapi
Install GNU Sed:            http://bugs.php.net/fix.php?id=24522&r=gnused

Reply via email to