I'm upgrading to slim v3. How should I use a database connection? I'm thinking about a service injected with pimple:
DBConnection
final class DBConnection {
private $db;
public function __construct() {
try {
// Code to open up a DB connection in $db var...
} catch (Exception $ex) {
// TODO $app->error ?
}
}
public function getDB() {
return $this->db;
}
}
index.php
$container = new \Slim\Container;
$container['db'] = function($container) {
$connection = new DBConnection();
return $connection->getDB();
};
What if the db connection raise a PDO (or generic) Exception? In v2 I had something like
$app->error
now what? I've defined a custom errorHandler as well, how can I somehow "redirect" the control over that route?