When i am using try catch block for example:
try{
require_once('../php/connect.php');
$dbh = db::getInstance();
// What i am trying to understand should i close the connection here before the header?
header("Location: x.php");
}
} catch(PDOException $e){
require_once('err.php');
}
$dbh = null; // Or should i close the connection here?
Is the “interpreter” even get after line “5”, Thank you all and have a nice day.
Since you are not using
exitafterheader()(which is recommended), your code will continue to execute.As such, it does not matter if you put in on line 4 or 10. Furthermore, as pointed out by prodigitalson, you do no need to explicitly close the database connection.