Reputation: 145
I don't want to use Doctrine or etc. So, I simply use the PDO. The problem is that I dont't know how to handle the exception: calling the $app->abort
to show it doesn't work outside the routes.
<?php
require_once __DIR__.'/../vendor/autoload.php';
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
$app = new Silex\Application();
//PDO
try {
$DBH = new PDO($PartCCTV_ini['db']['dsn'], $PartCCTV_ini['db']['user'], $PartCCTV_ini['db']['password']);
}
catch(PDOException $e) {
$app->abort(500, 'PDO Error : '.$e->getMessage());
}
...
$app->run()
?>
Upvotes: 1
Views: 325
Reputation: 145
//PDO
try {
$DBH = new PDO($PartCCTV_ini['db']['dsn'], $PartCCTV_ini['db']['user'], $PartCCTV_ini['db']['password']);
}
catch(PDOException $e) {
$Exception = $e->getMessage();
$app->before(function () use($Exception) {
throw new PDOException($Exception);
});
}
"Kolkhoz-style" (Russian), but it works!
Upvotes: 2