Is there a function for closing a mysql prepared statement with PDO?

你离开我真会死。 提交于 2019-12-30 23:38:07

问题


In mysqli prepared statements there ismysqli_stmt::close() (Closes a prepared statement):

$stmt->close();

I have searched php.net and the web and cannot find an alternative for PDO.

Is this possible?

And what are the benefits of using it at the end of each of your scripts?

I understand that,

$connection = null;

closes the connection to mysql, but what about closing the query?


回答1:


To free the result set you can apply basic PHP way.

If you are returning the results with PDOStatement::fetchAll() then you would need to unset() the variable to clear it:

$variable = $stmt->fetchAll();

unset($variable);
// or:
$variable = null; 

Or PDOStatement::closeCursor() (Closes the cursor, enabling the statement to be executed again.) may be helpful:

$success = $stmt->closeCursor();


来源:https://stackoverflow.com/questions/5685879/is-there-a-function-for-closing-a-mysql-prepared-statement-with-pdo

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!