/** * Execute a query and fetch first row as associative array * * @param string $query * @param array $parameters Query parameters * @return array * @throws \Phramework\Exceptions\DatabaseException * @example * ```php * $record = Database::executeAndFetch( * 'SELECT "id", "first_name" * FROM "user" * WHERE "id" = ? * LIMIT 1', * [$id] * ); * ``` */ public static function executeAndFetch($query, $parameters = [], $castModel = null) { try { return static::$adapter->executeAndFetch($query, $parameters); } catch (\Exception $e) { throw new DatabaseException('Database Error', $e->getMessage()); } }
/** * Execute a query and fetch first row as associative array * * @param string $query * @param array $parameters Query parameters * @param array $castModel * *[Optional]* Default is null, if set then * @return array Returns a single row * @throws Phramework\Exceptions\DatabaseException */ public function executeAndFetch($query, $parameters = [], $castModel = null) { $startTimestamp = time(); $exception = null; try { $result = $this->internalAdapter->executeAndFetch($query, $parameters); } catch (\Exception $e) { $exception = $e; } finally { //log $this->log($query, $parameters, $startTimestamp, $exception); if ($exception) { throw $exception; } } return $result; }