Add $limit parameter to $db->select method

This commit is contained in:
slawkens 2020-06-06 17:08:41 +02:00
parent 7469d520c9
commit 1c6b241239

View File

@ -91,16 +91,21 @@ 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 = substr($query, 0, -4);
if (isset($limit))
$query .=') LIMIT '.$limit.';';
else
$query .=');';
$query = $this->query($query);