目前,我按以下方式初始化数据库:
$di->set('db',function() use ($config){ return new \Phalcon\Db\Adapter\Pdo\MysqL( array( "host" => $config->database->host,"username" => $config->database->username,"password" => $config->database->password,"dbname" => $config->database->name ) ); });
但是当MysqL凭据错误或数据库不存在时,Phalcon返回空白页面而没有任何错误消息.这种情况真的很头疼,因为登录/密码/主机中的小错误导致几乎无法检测到的错误.
我以下面的代码结束:
$di->set('db',function() use ($config){ try { $db = new \Phalcon\Db\Adapter\Pdo\MysqL( array( "host" => $config->database->host,"dbname" => $config->database->name ) ); } catch (Exception $e) { die("<b>Error when initializing database connection:</b> " . $e->getMessage()); } return $db; });
请告诉我是否有更好的方法.