Jaycee
Jaycee

Reputation: 3

Is it okay to Add an exit; in if else statement before mysqli_close()?

is it okay to add an exit; in the if-else statement with mysqli_close(); at the end of the Line of code? The database connection will be closed?

Here is my code

<?php
if(isset($_POST['data'])){
//Mysqli Query
exit;
}else{
//Other mysqli query
}
mysqli_close($connection);
?>

Upvotes: 0

Views: 59

Answers (1)

ceejayoz
ceejayoz

Reputation: 180176

Yes, that's fine. Unless you're using persistent database connections, PHP will close the connection when you exit.

https://www.php.net/manual/en/mysqli.close.php

Open non-persistent MySQL connections and result sets are automatically closed when their objects are destroyed.

Upvotes: 2

Related Questions