From 1c6b241239d9d7857af962e474bf91b5db3e8b06 Mon Sep 17 00:00:00 2001 From: slawkens Date: Sat, 6 Jun 2020 17:08:41 +0200 Subject: [PATCH] Add $limit parameter to $db->select method --- system/libs/pot/OTS_Base_DB.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/system/libs/pot/OTS_Base_DB.php b/system/libs/pot/OTS_Base_DB.php index 9e34ba11..fb6d2362 100644 --- a/system/libs/pot/OTS_Base_DB.php +++ b/system/libs/pot/OTS_Base_DB.php @@ -91,17 +91,22 @@ abstract class OTS_Base_DB extends PDO implements IOTS_DB return $ret; } - public function select($table, $data) + public function select($table, $where, $limit = null) { - $fields = array_keys($data); - $values = array_values($data); + $fields = array_keys($where); + $values = array_values($where); $query = 'SELECT * FROM ' . $this->tableName($table) . ' WHERE ('; $count = count($fields); for ($i = 0; $i < $count; $i++) $query.= $this->fieldName($fields[$i]).' = '.$this->quote($values[$i]).' AND '; + $query = substr($query, 0, -4); - $query.=');'; + $query = substr($query, 0, -4); + if (isset($limit)) + $query .=') LIMIT '.$limit.';'; + else + $query .=');'; $query = $this->query($query); if($query->rowCount() != 1) return false;