dssqq64884 2014-10-16 10:24
浏览 356
已采纳

游标状态无效 - pdo_odbc FreeTDS SQL Server

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

  • 写回答

1条回答 默认 最新

  • douyue1926 2014-10-16 10:28
    关注

    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);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统