Mysqli语句的`close()`方法是什么? [英] What does the `close()` method of the Mysqli Statement?
问题描述
有人可以告诉我,例如,当您更新,插入,删除时,是否应该像 mysqli_stmt::close();
?我检查了PHP手册,却不了解close()
的实际作用.
Can someone tell me, when you for example update, insert, delete.. should you then close it like mysqli_stmt::close();
? I checked PHP manual and don't understand what close()
actually does.
示例:
$stmt = $dbh->prepare("SELECT `user_email` FROM `users` WHERE `user_email` = ? LIMIT 1");
$stmt->execute(array($email));
$stmt->close();
我的问题的下一部分是,例如,如果我在事务中执行的每个查询的每个execute()
之后,在事务中有多个更新查询我应该单独关闭它们吗? ...因为这是一个事务,所以不确定在每个execute()之后是否需要使用$stmt->close();
;还是只使用一个$stmt->close();
?
Next part of my question is, if as an example i had multiple update queries in a transaction after every execute()
for each query i am executing within the transaction should i close them individually ? ... because it's a transaction not sure i need to use $stmt->close();
after each execute(); or just use one $stmt->close();
after all of them ?
推荐答案
似乎您正在使用mysqli close方法. $ stmt-> close()方法只是关闭即可关闭先前打开的数据库连接( http://www.php.net/manual/en/mysqli.close.php ).
It seems like you are using mysqli close method. The $stmt->close() methode simply just closes closes the the previous opened database connect (http://www.php.net/manual/en/mysqli.close.php).
编辑:如果您使用的是PDO,我根本不明白,为什么您不利用命名参数而不是问号的可能性.这就是为什么很多人选择PDO而不是mysqli的原因-您可能对查询/语句有更好的综合了解.
If it's PDO you are using, I simply do not understand, why you dont take advantage of the possibility of having named parametres instead of question marks. That is, why a lot of people choose PDO instead of mysqli - you might have a better comprehensive view of the queries/statements.
这篇关于Mysqli语句的`close()`方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!