|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[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.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 22:00:02 2025 UTC |
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 ); // failsYou 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");