php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #18429 mssql_query() crashes on stored procedure using a cursor on query that contains
Submitted: 2002-07-19 02:16 UTC Modified: 2002-12-26 12:46 UTC
Votes:8
Avg. Score:3.8 ± 1.0
Reproduced:4 of 5 (80.0%)
Same Version:2 (50.0%)
Same OS:1 (25.0%)
From: hujbanan at yahoo dot com Assigned:
Status: No Feedback Package: MSSQL related
PHP Version: 4.3.0-dev OS: Win2000
Private report: No CVE-ID: None
 [2002-07-19 02:16 UTC] hujbanan at yahoo dot com
I use PHP statement mssql_query( "EXEC db_proc 1, 2, 3" ) {query B} to call stored procedure on MSSQL 2000 server, which produces output using cursor. Before it, I create global cursor using mssql_query( "DECLARE  rowset CURSOR GLOBAL SCROLL FOR $query" ) {query A}. I need dynamically choose executed query, so I can't declare cursor in stored procedure. Statement {A} creates global cursor which is fetched and dropped in SP db_proc {B}. When I use as $query SQL command 'SELECT id FROM store', it works fine. But if I use something like 'SELECT id+1 AS col FROM store', PHP function mssql_query crashes. However, both of sequences of SQL queries run without problems in SQL Query Analyzer (SQL 2k).

I found this problem on PHP version 4.2.0 for win32. I try latest version of PHP from http://snaps.php.net/win32/ (both, stable v4.2.2-dev and unstable v4.3.0-dev) but problem persists. I'm using Apache 1.3.20/PHP 4.2.0 on Win2k advanced server. I have step by step tryed Apache 2.0.39 with PHP v4.2.1, 4.2.2-dev and 4.3.0-dev, but with the same result.

Can you tell me, what is wrong? Is it PHP bug or mistake in PHP/Apache configuration? I used default settings of PHP and Apache, PHP extensions: dba, mssql & gd.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-07-19 04:55 UTC] sniper@php.net
version update
 [2002-07-19 08:24 UTC] hujbanan at yahoo dot com
I have tried new update of stable version, but with the same result, it doesn't work. I send to you some example of code, which cause troubles, because I believe, it can help you to debug this problem.

stored procedure:
ALTER PROCEDURE sp_fetch_row @row int = 1 AS
  OPEN GLOBAL rowset
  FETCH ABSOLUTE @row FROM GLOBAL rowset
  CLOSE GLOBAL rowset
  DEALLOCATE GLOBAL rowset
GO

php:
function fetch_row( $link, $query, $row = 1 ) {
  if ( mssql_query( "DECLARE rowset CURSOR GLOBAL SCROLL FOR $query", $link ) ) {
    if ( $result = mssql_query( "EXEC sp_fetch_row $row", $link ) ) {
      $row = mssql_fetch_assoc( $result );
      mssql_free_result( $result );
    } else
      mssql_query( 'DEALLOCATE GLOBAL rowset', $link );
  }

  return $row;
}

$result = fetch_row( $link, 'SELECT id, name FROM store', 3 );    // OK
$result = fetch_row( $link, 'SELECT id*2, name FROM store', 3 );  // fails
 [2002-07-19 08:52 UTC] sniper@php.net
please don't change the version to earlier if you already confirmed it to happen with the LATEST..
 [2002-07-19 09:56 UTC] hujbanan at yahoo dot com
I'm very sorry, I have to find PHP version, which do that correctly, so I've tried all available versions. Latest versions too. In combobox on 'Bugs Report - New' are only 4.1.2, 4.2.0, 4.2.1 and 4CVS-2002-07-19 versions selectable. Because of both latest versions (stable 4.2.2-dev and 4.3.0-dev) was uploaded to server snaps.php.net 2002/07/19, so I choose version 4CVS-2002-07-19.

I've tried new update of latest stable version (http://snaps.php.net/win32/php4-win32-STABLE-latest.zip), and it is still not work. May be it is caused with my bad configuration of Apache/PHP. Because of this little misunderstanding, I'm not sure, which version you are modifying, so I don't know, which one I need to download. Could you, please, send me, if it is corrected and which archive I should to download. Thank you for your patient.
 [2002-07-19 12:10 UTC] sniper@php.net
This is the snapshot for 4.3.0-dev:

http://snaps.php.net/win32/php4-win32-latest.zip

DO NOT REPLY unless you have _NEW_ information.
DO NOT TOUCH the version anymore!!!!

Also note that Apache2 is NOT stable for ANY use yet.
Use Apache 1.3.26 which is proven to actually work (with PHP)

 [2002-07-19 14:45 UTC] hujbanan at yahoo dot com
I download apache 1.3.26 from www.apache.org and latest PHP from listed URL, but it doesn't work. PHP still crashes. Both installed on Win 2000 Advanced Server.
 [2002-12-08 10:34 UTC] sniper@php.net
Please try using this CVS snapshot:

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


 [2002-12-24 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over 2 weeks, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2002-12-26 12:46 UTC] fmk@php.net
You can use mssql_execute() if you want to get results back from stored preocedures.

When you execute a command not returning data the MSSQL extension will close the transaction and releasse any declared variables. You can send more than one statement in a single query:

mssql_query("DECLARE rowset CURSOR GLOBAL SCROLL FOR $query
EXEC sp_fetch_row $row");
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 13:01:31 2024 UTC