From: Alexander Ebert Date: Fri, 23 Aug 2019 15:49:41 +0000 (+0200) Subject: Implemented `PreparedStatement::fetchList()` X-Git-Tag: 5.2.0_Beta_1~5 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=8ffd331c803dbf9de49781efcfbe1f25891be312;p=GitHub%2FWoltLab%2FWCF.git Implemented `PreparedStatement::fetchList()` See #3054 --- 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 4abe0333d6..a4b0675b12 100644 --- a/wcfsetup/install/files/lib/system/database/statement/PreparedStatement.class.php +++ b/wcfsetup/install/files/lib/system/database/statement/PreparedStatement.class.php @@ -23,7 +23,7 @@ class PreparedStatement { * database object * @var Database */ - protected $database = null; + protected $database; /** * SQL query parameters @@ -35,7 +35,7 @@ class PreparedStatement { * pdo statement object * @var \PDOStatement */ - protected $pdoStatement = null; + protected $pdoStatement; /** * SQL query @@ -221,6 +221,27 @@ class PreparedStatement { return $map; } + /** + * Returns a one-dimensional list of all rows holding only the value of the specified column. Please see + * `fetchAll()` if you simply want to read all rows into an array. + * + * @param string $column + * @return string[]|int[]|float[] + */ + public function fetchList($column) { + $list = []; + + while ($row = $this->fetchArray()) { + if (!array_key_exists($column, $row)) { + throw new \RuntimeException("The requested column '{$column}' is not contained in the result rows."); + } + + $list[] = $row[$column]; + } + + return $list; + } + /** * Counts number of affected rows by the last sql statement (INSERT, UPDATE or DELETE). *