Edit report at http://bugs.php.net/bug.php?id=46050&edit=1
ID: 46050 Updated by: fel...@php.net Reported by: RQuadling at GMail dot com Summary: odbc_next_result corrupts prepared resource -Status: Open +Status: Feedback Type: Bug Package: ODBC related Operating System: Windows XP SP3 PHP Version: 5.3.0alpha2 New Comment: Thank you for this bug report. To properly diagnose the problem, we need a backtrace to see what is happening behind the scenes. To find out how to generate a backtrace, please read http://bugs.php.net/bugs-generating-backtrace.php for *NIX and http://bugs.php.net/bugs-generating-backtrace-win32.php for Win32 Once you have generated a backtrace, please submit it to this bug report and change the status back to "Open". Thank you for helping us make PHP better. Previous Comments: ------------------------------------------------------------------------ [2010-04-12 17:40:35] RQuadling at GMail dot com Using PDO-ODBC is fine. // Connect to the SQL Server using a DNS-less connection. // $r_Connection = odbc_pconnect("Driver={SQL Server};Server={$s_Server};Database={$s_Database}", $s_Username, $s_Password); $r_Connection = new PDO("odbc:Driver={SQL Server Native Client 10.0};Server={$s_Server};Database={$s_Database}", $s_Username, $s_Password); // Prepare the statement. // $r_Statement = odbc_prepare($r_Connection, "EXEC {$s_Database}.dbo.{$s_StoredProc} ?"); $r_Statement = $r_Connection->prepare("EXEC {$s_Database}.dbo.{$s_StoredProc} ?"); // Execute the statement for each parameter. foreach($a_Params as $s_Param) { echo 'About to process : ', $s_Param, PHP_EOL; // $b_Executed = odbc_execute($r_Statement, array($s_Param)); $b_Executed = $r_Statement->execute(array($s_Param)); do { // while(False !== ($a_Row = odbc_fetch_array($r_Statement))) while(False !== ($a_Row = $r_Statement- >fetch(PDO::FETCH_ASSOC))) { print_r($a_Row); } } // while(True === ($b_MoreResults = odbc_next_result($r_Statement))); while(True === ($b_MoreResults = $r_Statement->nextRowset())); $r_Statement->closeCursor(); } ------------------------------------------------------------------------ [2008-10-24 08:58:35] j...@php.net Reclassified in correct category. And you should use PDO ODBC instead anyway. ------------------------------------------------------------------------ [2008-09-11 13:33:33] RQuadling at GMail dot com Description: ------------ Using PHP 5.3.0alpha3-dev (cli) (built: Sep 11 2008 09:01:08) Using ODBC to talk to Microsoft SQL Server 7. Using a prepared statement to run a Stored Procedure on the SQL server. Using the function odbc_next_result() to determine if there are more result sets after having retrieved the first result sets kills the prepared statement from re-use and results in an unhandled win32 exception. The SP is not the issue and as a test is the following code: CREATE PROCEDURE dbo.SimpleIdentity @s_Identity AS VARCHAR(500) AS SELECT @s_Identity AS [Simple Identity] GO Removing the odbc_next_result() loop makes everything work. The example code below is from a larger code which deals with getting data from an SP and caching the result(s). Currently I am unable to retrieve multiple result sets AND use stored procedures together. Reproduce code: --------------- <?php // Configure this script. $s_Server = 'BANDVULCSQL'; $s_Database = 'CONTRACTS'; $s_Username = 'sa'; $s_Password = 'sa'; $s_StoredProc = 'SimpleIdentity'; $a_Params = array ( 'Richard', 'Simon', 'John', ); /******************************************/ // Connect to the SQL Server using a DNS-less connection. $r_Connection = odbc_pconnect("Driver={SQL Server};Server={$s_Server};Database={$s_Database}", $s_Username, $s_Password); // Prepare the statement. $r_Statement = odbc_prepare($r_Connection, "EXEC {$s_Database}.dbo.{$s_StoredProc} ?"); // Execute the statement for each parameter. foreach($a_Params as $s_Param) { echo 'About to process : ', $s_Param, PHP_EOL; $b_Executed = odbc_execute($r_Statement, array($s_Param)); do { while(False !== ($a_Row = odbc_fetch_array($r_Statement))) { print_r($a_Row); } } while(True === ($b_MoreResults = odbc_next_result($r_Statement))); } Expected result: ---------------- About to process : Richard Array ( [Simple Identity] => Richard ) About to process : Simon Array ( [Simple Identity] => Simon ) About to process : John Array ( [Simple Identity] => John ) Actual result: -------------- About to process : Richard Array ( [Simple Identity] => Richard ) About to process : Simon and then an unhandled win32 exception in php.cli ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/bug.php?id=46050&edit=1