php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #17291 mssql_query does not update get_last_message
Submitted: 2002-05-17 11:58 UTC Modified: 2003-07-10 21:08 UTC
From: mgruetzner at rw3 dot com Assigned:
Status: Closed Package: Sybase (dblib) related
PHP Version: 4.3.1 OS: Linux
Private report: No CVE-ID: None
 [2002-05-17 11:58 UTC] mgruetzner at rw3 dot com
If you make the following calls in PHP 4.1.2 on Linux using freetds 0.53 to connect to a MS SQL Server 7 database:

mssql_query ("mystoredproc");
$msg = mssql_get_last_message ();
print $msg;

where "mystoredproc" is a stored procedure that returns N rows of data and calls the SQL function below to send a warning message:

raiserror ('QueryLimit',9,1)

you would expect the value of $msg to be "QueryLimit" after the call to mssql_query.  In fact, this is how it works on Windows but not on Linux using freetds.  I have debugged this issue on both the freetds and php software and found the following.  On Freetds, the message number that gets returned from SQL is 50000 which when stored as a 16-bit signed integer is a negative value in the freetds code, so the freetds code ignores the message.  I modified the freetds code to NOT ignore negative message numbers but to go ahead and pass those messages on to the appropriate callback function in PHP.  That helped matters, but there was still an issue in the php code in the "sybase_query" function in php_sybase_db.c.  Basically, what is happening is that in the case described above, you receive 2 sets of database results as a result of the query, but the sybase_query function is only reading the first set of results.  To remedy the problem, I modified the sybase_query function to save the results of the first call to dbresults().  Then, after reading all the rows of data from the first set of results, I checked the result of the first call to dbresults.  If it is not set to NO_MORE_RESULTS, I call dbresults again to read the second set of results, which in this case, is the warning message.  By doing so, this causes the freetds software to recognize the message and callback PHP with the message.  I have tested these fixes on Linux and they seem to work find I can email the source code for the fix if you are interested....


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-03-04 20:19 UTC] sniper@php.net
Please try using this CVS snapshot:

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


And as it propably isn't fixed in it, can you please
provide the patch for this snapshot's php_sybase_db.c ?

 [2003-03-06 07:13 UTC] mgruetzner at rw3 dot com
I created a patch using diff -u that can be applied with:
patch php_sybase_db.c php_sybase_db.patch.  It can be found at:

http://www.xnitech.com/php_sybase_db.patch
 [2003-07-10 21:08 UTC] sniper@php.net
Patch applied.

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 19:01:29 2024 UTC