Edit report at https://bugs.php.net/bug.php?id=24522&edit=1
ID: 24522 Comment by: paul at lumient dot com dot au Reported by: cdcr440 at hotmail dot com Summary: MSSQL: "Changed database context to" error when running query Status: Not a bug Type: Bug Package: MSSQL related Operating System: WinNT PHP Version: 4.3.1 Block user comment: N Private report: N New Comment: Just had this issue too. The problem was I was not passing the connection object to mssql_query(...). As a result the query failed to return anything and when I detected this I showed an error. When I looked at the mysql_error(...) return value it displayed this message (even though it was just a low-level warning) because it was the last message that had been logged. When I passed in a valid connection object to mssql_query it all went away! Previous Comments: ------------------------------------------------------------------------ [2011-09-10 05:22:27] rayphilip3 at gmail dot com Hi Cjrogala, Could you tell how you had solved this issue? My application also has this strange problem Thanks Ray ------------------------------------------------------------------------ [2011-07-10 18:42:00] cjrogala at gmail dot com I am an idiot. Please disregard my post. ------------------------------------------------------------------------ [2011-07-10 18:34:22] cjrogala at gmail dot com You may want to reopen this issue. I am inserting data into MS SQL Server 2008r2 and using PHP 5.2; and the same error occurs. The positive is that the error did not prevent the data from being inserted into the database, but it did display the same error message. I did not attempt to change the timeout since this is a much later version. I also noticed this issue in a few different location on the web. I am logging into the database as the sa and like I said, the data is making into the database; but the error still appears when validating the result of the query. Unlike the previous post, I will not provide a credentials, but I know it's not a connection error since the data is getting into the database. Here is my code: $tsql = "USE littleliam INSERT INTO [littleliam].[dbo].[tbl_blogPosts] ([postText] ,[created] ,[createdBy] ,[approved]) VALUES ('" .$postText ."', GETDATE(), " .$author .", " .$approvalStatus .")"; //Used to validate the query by running it in SQL Server Management studios echo $tsql; //Prepare and execute the statement. mssql_select_db('littleliam'); $insertReview = mssql_query($tsql, $msServerLink); if (!$res) { print("SQL statement failed with error:\n"); print(" ".mssql_get_last_message()."\n"); } else { print("One data row inserted.\n"); } mssql_close($msServerLink); My connection script is: $msServerLink = mssql_connect($db_server, $db_user, $db_pass); The only thing I could think of is selecting the database in the connect function. Can a database be selected in the mssql_connect function? ------------------------------------------------------------------------ [2003-07-13 10:48:25] sni...@php.net Temporarily closing. :) ------------------------------------------------------------------------ [2003-07-10 04:03:09] cdcr440 at hotmail dot com Thank you very much for that. Unfortunately, I can't check that this fixes the problem because it's gone today and I didn't manage to find a query that fails. As I said it's unpredictable and appears/disappears regularly. I've increased the timeout and I'll see if the problem comes back again. Sorry to have wasted your time, I think you can temporarily close this bug report. ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at https://bugs.php.net/bug.php?id=24522 -- Edit this bug report at https://bugs.php.net/bug.php?id=24522&edit=1