From 94a5edc1eb0ace85fdead478327b57e4a35d78cd Mon Sep 17 00:00:00 2001 From: "Michael Kaufmann (d00p)" Date: Wed, 6 Nov 2013 10:51:50 +0100 Subject: [PATCH] implement pexecute_first to PDO database class to return a result right away Signed-off-by: Michael Kaufmann (d00p) --- lib/classes/database/class.Database.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/classes/database/class.Database.php b/lib/classes/database/class.Database.php index 29ef2066..bf554058 100644 --- a/lib/classes/database/class.Database.php +++ b/lib/classes/database/class.Database.php @@ -69,6 +69,22 @@ class Database { } } + /** + * Wrapper for PDOStatement::execute so we can catch the PDOException + * and display the error nicely on the panel - also fetches the + * result from the statement and returns the resulting array + * + * @param PDOStatement $stmt + * @param array $params (optional) + * @param bool $showerror suppress errordisplay (default true) + * + * @return array + */ + public static function pexecute_first(&$stmt, $params = null, $showerror = true) { + self::pexecute($stmt, $params, $showerror); + return $stmt->fetch(PDO::FETCH_ASSOC); + } + /** * returns the number of found rows of the last select query *