我不想使用条令等。所以,我只是使用PDO。问题是我不知道如何处理异常:调用$app->abort
以表明它在路由之外不工作。
<?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()
?>
//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);
});
}
"科尔霍兹风格"(俄语),但它有效!