From b9cb4e50fcc2e286b08a832e114d884db5a62cd8 Mon Sep 17 00:00:00 2001 From: Pierre Date: Sat, 17 Feb 2018 19:25:21 +0100 Subject: [PATCH] Created splitConditionsArray --- classes/DBLibrary.php | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/classes/DBLibrary.php b/classes/DBLibrary.php index 95fc6c9..dc96b74 100755 --- a/classes/DBLibrary.php +++ b/classes/DBLibrary.php @@ -520,6 +520,34 @@ class DBLibrary { exit($this->echoPDOException($e)); } } + + /** + * Convert an array of conditions into a condition string and an array of conditions values + * + * @param array $conditions The conditions to convert + * @return array The result + */ + public function splitConditionsArray(array $conditions) : array { + + //Create the string + $sql = ""; + $values = array(); + + //Process each element + foreach($conditions as $field => $value){ + + //Add AND separator if required + if(strlen($sql) > 0) + $sql .= " AND "; + + $sql .= $field . " = ?"; + $values[] = $value; + } + + //Return the result + return array($sql, $values); + + } /** * Echo an exception