|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2008-09-11 13:33 UTC] 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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 13:00:01 2025 UTC |
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(); }