Is a call to PDOStatement::closeCursor() necessary if the statement object is unset anway?

后端 未结 2 2283
花落未央
花落未央 2021-02-20 13:51

I\'m utilizing a Mysql based PDO connection with PDOStatement (::prepare(); ::execute()) and I\'ve run over some code from a

2条回答
  •  隐瞒了意图╮
    2021-02-20 14:49

    My understanding of PDOStatement::closeCursor() is that it clears the result of a executed query. But not affects a PDOStatement at all (just the result of its execution).

    From the PHP Documnetation about this method:

    frees up the connection to the server so that other SQL statements may be issued

    and

    This method is useful for database drivers that do not support executing a PDOStatement object when a previously executed PDOStatement object still has unfetched rows.

    let me assume that you should make after every execution and fetch of all data you need form the current query execution a call to the PDOStatement::closeCursor() method. I think the MySQL driver for PDO does this automatically but there seems to be problems with some drivers which does not automatically free up the result.

    So if you switch to another DB driver which does not free up the pending result of the query you run into an error.

提交回复
热议问题