Using SQL Server stored procedures with empty resultsets in PHP 5.4 -


i use php 5.4 microsofts 3.0 drivers execute stored procedures in sql server 2008. works fine until execute procedure isn't returning result doing update. error message is:

sqlstate[imssp]: active result query contains no fields. 

the procedure isn't working boils down simple code:

create procedure [dbo].[sp_communication_increase_trials]     @comid bigint = null begin      set nocount on      if not @comid null     begin         update communication set communicationtrials = communicationtrials + 1 id = @comid;     end;  end 

the php-code barfs @ fetchall method when executing procedure above:

if ($stmt->execute()) {     {         $rowset = $stmt->fetchall(pdo::fetch_assoc);         if ($rowset) {             $results[] = $rowset;         }     } while ($stmt->nextrowset());  } return $results; 

however, adding simple select after update-statement in procedure makes work, shouldn't necessary.

the solution came add boolean argument method executing procedure , returning results indicate if returning result set expected. boolean default set true unless explicitly specified false.

this way fetchall method isn't called when told not to.

if ($stmt->execute() && $do_return_rowsets) {     {         $rowset = $stmt->fetchall(pdo::fetch_assoc);         if ($rowset) {             $results[] = $rowset;         }     } while ($stmt->nextrowset());  }  

it's perhaps not more fair contract between php code , procedure specifies rowset returned or not.


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

javascript - jQuery .height() return 0 when visible but non-0 when hidden -