public static function findOne($id) { $sql = 'SELECT * FROM ' . static::getTable() . ' WHERE articleId = :articleId'; $db = new Database(); $result = $db->selectOne(static::class, $sql, [':articleId' => $id]); if ($result == false) { throw new MyException('E404'); } else { return $result; } }
public function delete() { $sql = 'DELETE FROM ' . static::getTable() . ' WHERE articleId = :articleId'; $db = new Database(); $result = $db->execute($sql, [':articleId' => $this->articleId]); if ($result == false) { throw new MyException('E404'); } else { return $result; } }
/** * Bootstrap any application services. * * @return void */ public function boot(Request $request) { View::addExtension('tpl', 'blade'); // check dotenv if (!file_exists(base_path('.env'))) { throw new PrettyPageException(trans('setup.file.no-dot-env'), -1); } try { // check database config Database::prepareConnection(); } catch (\Exception $e) { throw new PrettyPageException(trans('setup.database.connection-error', ['msg' => $e->getMessage()]), $e->getCode()); } // skip the installation check when setup or under CLI if (!$request->is('setup') && !$request->is('setup/*') && PHP_SAPI != "cli") { $this->checkInstallation(); } }
public static function checkSess() { $sql = 'SELECT userId FROM ' . static::getTable() . ' WHERE userSess = :userSess'; $db = new Database(); return $db->selectOne(static::class, $sql, [':userSess' => $_SESSION['sess']]); }
<?php require_once __DIR__ . '/../vendor/autoload.php'; use Silex\Application; use Silex\Provider\ServiceControllerServiceProvider; use DerAlex\Silex\YamlConfigServiceProvider; use App\Services\Database; $app = new Application(); $app->register(new ServiceControllerServiceProvider())->register(new YamlConfigServiceProvider(__DIR__ . '/config/config.yml')); $database = new Database($app['config']); $app['connection'] = $database->getCapsule()->getConnection('default'); /** * @param $app * @param $shortName * @return string */ function controller($app, $shortName) { list($shortClass, $shortMethod) = explode(':', $shortName, 2); $className = sprintf('App\\Controller\\%sController', ucfirst($shortClass)); if (!isset($app[$shortClass . '.controller'])) { $app[$shortClass . '.controller'] = $app->share(function () use($app, $className) { return new $className($app); }); } return $shortClass . '.controller:' . $shortMethod . 'Action'; } return $app;