| Server IP : 185.252.147.100 / Your IP : 216.73.216.43 Web Server : nginx/1.27.3 System : Linux mitrofanov.ru 6.1.0-37-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.140-1 (2025-05-22) x86_64 User : mitr ( 1000) PHP Version : 8.2.29 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /www/html/kanboard/libs/SimpleValidator/Validators/ |
Upload File : |
<?php
namespace SimpleValidator\Validators;
use PDO;
class Unique extends Base
{
private $pdo;
private $primary_key;
private $table;
public function __construct($field, $error_message, PDO $pdo, $table, $primary_key = 'id')
{
parent::__construct($field, $error_message);
$this->pdo = $pdo;
$this->primary_key = $primary_key;
$this->table = $table;
}
public function execute(array $data)
{
if ($this->isFieldNotEmpty($data)) {
if (! isset($data[$this->primary_key])) {
$rq = $this->pdo->prepare('SELECT 1 FROM '.$this->table.' WHERE '.$this->field.'=?');
$rq->execute(array($data[$this->field]));
}
else {
$rq = $this->pdo->prepare(
'SELECT 1 FROM '.$this->table.'
WHERE '.$this->field.'=? AND '.$this->primary_key.' != ?'
);
$rq->execute(array($data[$this->field], $data[$this->primary_key]));
}
$result = $rq->fetchColumn();
if ($result == 1) { // Postgresql returns an integer but other database returns a string '1'
return false;
}
}
return true;
}
}