2

We're running a completely nonchalant query and are getting the following error:

PDOException : SQLSTATE[24000]: Invalid cursor state: 0 [FreeTDS][SQL Server]Invalid cursor state (SQLExecute[0] at /builddir/build/BUILD/php-5.5.13/ext/pdo_odbc/odbc_stmt.c:254)

From PHP we're using the pdo_odbc library to connect via FreeTDS to SQLServer 2008

Raptor
  • 53,206
  • 45
  • 230
  • 366
Rob Forrest
  • 7,329
  • 7
  • 52
  • 69

1 Answers1

8

It transpires that it was the preceding query that was causing problems. We were using:

$pdo_statement->fetch(\PDO::FETCH_ASSOC);

to get out a single row but not doing anything with it after then. This was leaving a cursor open which was then throwing the error then next time any query was executed. For us, closing the cursor before the next query was the way forward.

$pdo_statement->closeCursor();

It's also worth noting that using fetchAll() (in the preceding query) is also a fix as this does not leave a cursor open.

$pdo_statement->fetchAll(\PDO::FETCH_ASSOC);
Rob Forrest
  • 7,329
  • 7
  • 52
  • 69