php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #34784 Changed database context error when SELECT > 33 columns
Submitted: 2005-10-07 22:53 UTC Modified: 2016-10-15 23:07 UTC
Votes:27
Avg. Score:4.6 ± 0.7
Reproduced:20 of 21 (95.2%)
Same Version:7 (35.0%)
Same OS:7 (35.0%)
From: jwall at webpeak dot com Assigned:
Status: Wont fix Package: MSSQL related
PHP Version: 5CVS-2005-10-08 (snap) OS: Windows XP
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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: jwall at webpeak dot com
New email:
PHP Version: OS:

 

 [2005-10-07 22:53 UTC] jwall at webpeak dot com
Description:
------------
PHP 5.05/Sybase 12.53/php_mssql.dll

When doing a SELECT with > 33 columns, error:

[Native Error: Changed database context to 'my_db'.]

If the SQL is input via isql it works with no errors.

Reproduce code:
---------------
$link=mssql_pconnect('10.37.3.20,11222','sa','');
mssql_select_db('my_db',$link);

// limit of 33 columns allowed in select (so this fails)
$result=mssql_query("SELECT pr_0_6.prRN, pr_0_6.prDO, pr_0_6.prAC, pr_0_6.prCS, pr_0_6.prUS, pr_0_6.prHN, pr_0_6.prHS, pr_0_6.prSS, pr_0_6.d22, pr_0_6.d23, pr_0_6.d24, pr_0_6.d53, pr_0_6.l13, pr_0_5.prRN, pr_0_5.prDO, pr_0_5.prAC, pr_0_5.prCS, pr_0_5.prUS, pr_0_5.prHN, pr_0_5.prHS, pr_0_5.prSS, pr_0_5.d20, pr_0_5.d21, pr_0_5.d74, pr_0_5.d177, pr_0_5.d75, pr_0_5.d85, pr_0_5.d37, pr_0_5.d76, pr_0_5.d173, pr_0_5.d219, pr_0_5.d143, pr_0_5.d40, pr_0_5.d38, pr_0_5.d39, pr_0_5.d272, pr_0_5.d273, pr_0_5.d302 FROM pr_0_6, pr_0_5 WHERE pr_0_5.d21 LIKE 'A%' AND pr_0_6.l13=pr_0_5.prRN");

if (!$result) {
    plog('Could not execute query ' . mssql_get_last_message());
}
while($row=mssql_fetch_row($result)) {
    plog("row: " . dumpVar($row));
}
mssql_close($link);


Expected result:
----------------
Expected results is a log with each results array for every record returned. If I reduce the SELECT to < 34 then expected results are returned.

Actual result:
--------------
A log indicating the error:

Could not execute query Changed database context to 'my_db'.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-10-08 01:33 UTC] sniper@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5-win32-latest.zip


 [2005-10-08 02:32 UTC] jwall at webpeak dot com
I tried http://snaps.php.net/win32/php5-win32-latest.zip (5.1.0RC2-dev). This yields the same results.
 [2005-10-08 14:27 UTC] sniper@php.net
Frank, can you check this out?

 [2006-03-16 03:42 UTC] mcollard at hotmail dot com
This also happens for me in PHP 4.4.0 build of MSSQL.dll.
 [2006-03-24 21:15 UTC] zane dot wright at langley dot af dot mil
I also have the problem using 5.0.3 and a combination of PEAR's LiveUser using DB.

It can be reproduced with a 
$db =& DB::connect($dsn, $options);
var_dump($db->query('INSERT INTO liveuser_users_seq (vapor) VALUES (0)'));
 [2006-06-16 14:13 UTC] hectprjazz at hotmail dot com
extension of PHP 4.4.x (mssql.dll) = SQL Server 2000

extension of PHP 4.3.x (mssql.dll) = SQL Server 7
 [2006-06-16 14:14 UTC] hectorjazz at hotmail dot com
Corrected
 [2006-08-07 20:25 UTC] haunw at spcollege dot edu
I have this same issue on PHP 4.3.11(running as CGI) on Windows2000 server.

Happens intermittently.  Only pattern seems to be that it is when SQL Server is running a bit slower.
 [2007-07-03 23:39 UTC] vollmer at ampache dot org
I'm running into this same issue with large result sets. 

I am running a Debian ETCH server with Apache2/PHP5.2
dpkg --list | grep "php" 
ii  libapache2-mod-php5               5.2.0-8+etch4                   server-side, HTML-embedded scripting languag
ii  php-pear                          5.2.0-8+etch4                   PEAR - PHP Extension and Application Reposit
ii  php5-cli                          5.2.0-8+etch4                   command-line interpreter for the php5 script
ii  php5-common                       5.2.0-8+etch4                   Common files for packages built from the php
ii  php5-curl                         5.2.0-8+etch4                   CURL module for php5
ii  php5-gd                           5.2.0-8+etch4                   GD module for php5
ii  php5-ldap                         5.2.0-8+etch4                   LDAP module for php5
ii  php5-mcrypt                       5.2.0-8+etch4                   MCrypt module for php5
ii  php5-mysql                        5.2.0-8+etch4                   MySQL module for php5
ii  php5-snmp                         5.2.0-8+etch4                   SNMP module for php5
ii  php5-sybase                       5.2.0-8+etch4                   Sybase / MS SQL Server module for php5

The exact error I am seeing is
Query: SELECT * FROM L_U_t_State WHERE Status='1' (51 Rows returned)
Error: Changed database context to 'RMS'.

Complexity or speed of query doesn't appear to matter, my larger multi-table selects/joins/unions do not produce the same error. 

PHP Code that is producing the error message
<?php
/* Run the query*/
$result = mssql_fetch_assoc($result_resource);

                if (!$result) { 
                        debug_event('num_rows','Failed: ' . $sql .  mssql_get_last_message(),'1'); 
                } 

?>


-Karl Vollmer
 [2007-09-05 17:18 UTC] php at blazemonger dot com
I am seeing this error on *every* MSSQL query under PHP 5.2.2, on Windows 2003 Server x64, in the apache 2.2.4 error log file.
 [2008-03-06 18:45 UTC] arn_schw at yahoo dot com
Hi , 
I've written this code to use the data stored in the data-base named moviesite. The result is supposed to print the names of three different movies each one time.But,I get each 51 times I couldn't get where the error is present.So,please help me in rectifying my mistake......



<?php

//connecting to mysql
$connect = mysql_connect ( "localhost" , "root" , "") 
                   or die ( " You can't be connected to the server " ) ;
 
mysql_select_db (moviesite) ; 

$result = "SELECT movie_name , movie_year " . 
                "FROM movie " . 
                "WHERE movie_year > 1900 " . 
                "ORDER BY movie_name " ; 

$res = mysql_query ( $result ) 
                 or die ( mysql_error ( ) ) ; 


$st = 0 ; 

while( $ress = mysql_fetch_assoc ( $res ) )
{
 extract ( $ress ) ;
  echo "$movie_name" ; 
  echo "<br>" ; 
 $st = $st+1 ; 
}

echo "Finally the number of times it is printed is....".$st ; 

?>
 [2009-03-10 14:00 UTC] markus_hay at quantumdigital dot com
This bug has not been fixed and it's driving me absolutely nuts as I can not seem to reproduce it in a non-production environment to find a workaround. It happens on UPDATEs, INSERTs, SELECTs, etc., and it's completely random.

I don't know if it's a PHP issue or a PEAR issue, but as of PHP 5.2.5 and PEAR 1.7.2 the so-called informative message of "Changed database context to ..." is still appearing. OS is Windows Server 2k3 and database is MS SQL Server 2005.


The following settings are used in php.ini:
===========================================
mssql.min_error_severity = 10
mssql.min_message_severity = 10


Here is some example code:
==========================
$sSql = 'UPDATE Table SET iNumber = 5 WHERE iRecordId = 666';
if (PEAR::isError($oResults = $rDbConn->query($sSql))) {
     die($oResults->getMessage());
}


Typical output would be:
========================
[Native code: 0]
[Native message: Changed database context to 'TableName'.]


Is this ever going to get fixed?
 [2009-12-04 20:59 UTC] chrisgenrich at bmminvestments dot com
I was getting this error with a long running query and modified the php.ini to the following:

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

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


It's possible that lower settings could work as well...
 [2011-02-05 19:19 UTC] nkrsaxena at gmail dot com
This Bug is driving me crazy man, I am using
RHEL 5
Apache 2.0 server handler
Mysql 5.0
And trying to install PHP5.3.5 
installed all necessary file, now i use to connect to MSSQL server, my script 
shows
DB connected
DB selected

while performing Query it return "Changed database context XXXXXXX"
i have checked the same query on below two and running perfect
1. MSSQL terminal running file
2. Ran same script with all settings except PHP version 4.3.2 and 5.1.6

I tried the with RPM's as well but no luck. Googled a lot but no solution for 
the same.
 [2011-03-07 19:28 UTC] esflores at gmail dot com
Same problem but I found a valid solution to SP cases
Problem:
$proc = mssql_init("SP_Test");
mssql_bind($proc,"@var1",$_POST['var1'],SQLVARCHAR);
mssql_bind($proc,"@var2",$_POST['var2'],SQLVARCHAR);
$res = mssql_execute($proc) or die("ERROR: ".mssql_get_last_message());
//Output: Changed database context to 'DBNAME'

Solution:
$res = mssql_query("EXEC SP_Test '".$_POST['var1']."','".$_POST['var2']."'");
 [2014-12-29 01:04 UTC] kalle@php.net
-Status: Assigned +Status: Open -Assigned To: fmk +Assigned To:
 [2016-10-15 23:07 UTC] kalle@php.net
-Status: Open +Status: Wont fix
 [2016-10-15 23:07 UTC] kalle@php.net
With MSSQL being removed from PHP as of PHP7.0, and ext/mssql not having a maintainer, I'm gonna close this report as a Won't fix, until maybe one day it will find a new maintainer.

Alternatively you can use sqlsrv from Microsoft if you are on Windows, or pdo_dblib if you are on Unix.
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Thu Nov 26 01:01:23 2020 UTC