/** * @throws \Exception * @return array */ public function getCountries() { $result = []; /** @var \SlickFW\Service\Db $dbService */ $dbService = Setup::getInstance('Website')->get(['Database' => 'default']); try { $db = $dbService->getAdapter(); } catch (\Exception $e) { throw $e; } $sth = null; if (isset($db)) { $sth = $db->prepare($dbService->select('Country', ['Name', 'Continent', 'Region'])); /** @var $sth \PDOStatement */ if ($sth instanceof \PDOStatement) { if ($sth->execute()) { $result = $sth->fetchAll(\PDO::FETCH_OBJ); } else { $err = $sth->errorInfo(); } } else { $err = $db->errorInfo(); } if (isset($err) && null !== $err[1] && null !== $err[2]) { // log any database-error that might have occured Setup::getInstance('Website')->get(['Logger' => 'file'])->error('[Code: ' . $err[1] . '] ' . $err[2]); } } return $result; }
/** * fetch albums from DB "albums" and Table "album" */ public function getAlbums() { $db = new Albums(); try { $tableData = $db->getAlbums(); } catch (\Exception $e) { /** @var \SlickFW\Error\Logger $log */ $log = Setup::getInstance('Website')->get(['Logger' => 'file']); $log->error($e, Type::E_USER_EXCEPTION); } finally { if (isset($tableData)) { $this->add(['_testData' => ['albums' => $tableData]]); } else { $this->add(['_testData' => ['albums' => ['error' => 'Database-Error']]]); } } }