Drake Boein
Drake Boein

Reputation: 117

Is die() in php will close MYSQL connection automatically?

I am sorry if this is duplicate question. I have been searching for some threads but cannot find the suitable one. I just need clarficiation from many master. Since learning about an half year ago. I always use die() if there is an error in Mysql connection or something went wrong. I have been independent to this function

So my question: Is it alright to use die() on closing connection? For example here is my code

$sql = "SELECT age FROM db_name WHERE name=?";
$process = $conn->prepare($sql);
$process->bind_param('s',$name);
$process->bind_result($age);
$process->execute() or die("Error: ".$conn->error);
$process->store_result();
if($process->num_rows==0){
die('no data');
}
else{
$process->fetch();
}
$process->close();

I really appreciate any feedback because I want all my codes are light for memory. Thank you.

Upvotes: 1

Views: 325

Answers (1)

bobiczeq
bobiczeq

Reputation: 93

MySQL connection is closed when php script execution is ended.

Upvotes: 1

Related Questions