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

后端 未结 2 2276
花落未央
花落未央 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:37

    pdo_mysql_stmt_dtor() runs the same cleanup operations as pdo_mysql_stmt_cursor_closer(), so as long as the statement object is either explicitly unset or goes out of scope, the operations will always be performed.

    It is therefore not strictly necessary to call closeCursor() if the statement is about to be destroyed anyway. Personally I would do it anyway as I like to be explicit for readability, but that comes down to personal stylistic preferences.

    Based on the references above, this can only be said for certain about PDO_mysql - for other drivers this may not hold true.

提交回复
热议问题