What does the `close ()` method of a Mysqli expression do?

Can someone tell me when you, for example, update, paste, delete .. if you then close it, like mysqli_stmt::close(); ? I checked the PHP manual and did not understand what close() actually does.

Example:

 $stmt = $dbh->prepare("SELECT `user_email` FROM `users` WHERE `user_email` = ? LIMIT 1"); $stmt->execute(array($email)); $stmt->close(); 

The next part of my question: if as an example I had several update requests in a transaction after each execute() for every request that I execute in a transaction should I close them separately? ... because this transaction is not necessary, I need to use $stmt->close(); after each execute (); or just use one $stmt->close(); after all of them?

+7
php mysqli
Apr 14 '12 at 23:25
source share
2 answers

It looks like you are using the mysqli close method. The $ stmt-> close () method simply closes the closure of the previous open database connection ( http://www.php.net/manual/en/mysqli.close.php ).

EDIT: If you use PDO, I just don’t understand why you are not using the option to use the named parameters instead of question marks. This is why many people choose PDO instead of mysqli - you may have a more complete view of the queries / statements.

+3
Apr 14 '12 at 23:37
source share

There is no close () method for PDO, instead, to close the connection, you simply set the database variable to zero - this will close the connection.

 $stmt = null; 

To answer the second question, you only need to close the connection once. After completing all the queries that need to be performed in the database.

+9
Apr 14 2018-12-12T00:
source share



All Articles