Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PDO dblib nextRowset not working

I'm in the process of converting a PHP application from running in a Windows environment to a Linux based environment.

It utilises PDO to run Stored Procedures against a Microsoft SQL Server database.

So, I've installed and configured PHP 5.6.22, Apache, freetds and pdo dblib to facilitate the application.

Most stored procedure executions are working perfectly. Except ones that return multiple rowsets.

When I call $pdo->nextRowset(), I get this fatal error:

SQLSTATE[HY000]: General error: PDO_DBLIB: dbresults() returned FAIL

The only reference I can find to this was a bug reported in PHP 5.6.9 that was fixed.

However, I am getting the same issue in PHP 5.6.22.

Does anyone have any ideas why this is happening and how I can resolve it?

like image 359
Jamesking56 Avatar asked Jun 24 '16 11:06

Jamesking56


1 Answers

Are you fetching data with PDO::fetch or PDO::fetchAll ? Because if you use the "fetch" method and don't reach the end of the rows PDO::nextRowset() will fail (I don't know why, it just happened to me).

So, for me works to force to scan all rows until PDO::fetch returns false, then PDO::nextRowset() will execute normally.

It means that if you have only one row in a rowset you must call PDO::fetch at least two time (1 for retrieve data and 1 to return false) and then pass to next rowset.

like image 141
Simone Pessotto Avatar answered Sep 22 '22 09:09

Simone Pessotto