From 6f565d8631635a1fa2d6f50d168b96730193a3e6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Sat, 3 Jan 2015 21:40:05 +0100 Subject: [PATCH] Add PreparedStatement::fetchSingleRow() and fetchSingleColumn() --- .../statement/PreparedStatement.class.php | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/wcfsetup/install/files/lib/system/database/statement/PreparedStatement.class.php b/wcfsetup/install/files/lib/system/database/statement/PreparedStatement.class.php index c2bf3f995c..efd46428b4 100644 --- a/wcfsetup/install/files/lib/system/database/statement/PreparedStatement.class.php +++ b/wcfsetup/install/files/lib/system/database/statement/PreparedStatement.class.php @@ -121,6 +121,42 @@ class PreparedStatement { return $this->fetch($type); } + /** + * Fetches the next row from a result set in an array. + * Closes the 'cursor' afterwards to free up the connection + * for new queries. + * Note: It is not possible to fetch further rows after calling + * this method! + * + * @param integer $type fetch type + * @return mixed + * @see \wcf\system\database\statement\PreparedStatement::fetchArray() + */ + public function fetchSingleRow($type = null) { + $row = $this->fetchArray($type); + $this->closeCursor(); + + return $row; + } + + /** + * Returns the specified column of the next row of a result set. + * Closes the 'cursor' afterwards to free up the connection + * for new queries. + * Note: It is not possible to fetch further rows after calling + * this method! + * + * @param integer $columnNumber + * @return mixed + * @see \PDOStatement::fetchColumn() + */ + public function fetchSingleColumn($columnNumber = 0) { + $column = $this->fetchColumn($columnNumber); + $this->closeCursor(); + + return $column; + } + /** * Fetches the next row from a result set in a database object. * -- 2.20.1