protected function __construct($table, $pk) { $this->db = SqlDb::app(); $this->table = $table; $this->pk = $pk; $this->errors = []; }
private function unique($pairs, $pk = null) { $primary_key = $this->rules['pk']; $query_pairs = []; foreach ($pairs as $key => $value) { $query_pairs[] = "{$key}=:{$key}"; } $query = implode(' OR ', $query_pairs); if ($pk == null) { $result = SqlDb::app()->select("SELECT * FROM {$this->table} WHERE {$query}", $pairs); } else { $result = SqlDb::app()->select("SELECT * FROM {$this->table} WHERE ({$query}) AND {$primary_key}<>{$pk}", $pairs); } return $result; }