Browse Source

added PDO::fetchValuesListByKey

Piotr Labudda 8 years ago
parent
commit
526f201e29
1 changed files with 6 additions and 0 deletions
  1. 6 0
      SE/se-lib/Core/Pdo.php

+ 6 - 0
SE/se-lib/Core/Pdo.php

@@ -450,6 +450,12 @@ EOF_STRUCT_MYSQL;
 		}, $this->fetchAll($sql, $values));
 	}
 
+	public function fetchValuesListByKey($sql, $key, $values = []) { // for sql like `select ID from ...` @returns array of ID
+		return array_map(function ($row) {
+			return reset($row);
+		}, $this->fetchAllByKey($sql, $key, $values));
+	}
+
 	public function fetchFirst($sql, $values = []) { // fetch only first row
 		$sth = $this->prepare($sql);
 		if (!empty($values)) {