include_once "devsql.php";
class probe {
- private devsql $db; // devsql database instance
- private string $table; // table name
+ private devsql $db; // devsql database instance
+ private string $table; // table name
- private array $where = []; // WHERE conditions
- private array $params = []; // parameters for prepared statements
+ private ?string $where = null; // WHERE conditions
- private ?string $order = null; // ORDER BY clause
- private ?int $limit = null; // LIMIT for pagination
- private int $offset = 0; // OFFSET for pagination, internal only
+ private ?string $order = null; // ORDER BY clause
+ private ?int $limit = null; // LIMIT for pagination
+ private int $offset = 0; // OFFSET for pagination, internal only
/**
* Constructor
/**
* Add a WHERE condition
*/
- public function where(string $column, string $operator, $value): self
+ public function where(string $datawhere): self
{
- $param = ':' . $column . count($this->where);
- $this->where[] = "$column $operator $param";
- $this->params[$param] = $value;
+ $this->where = $datawhere;
return $this;
}
$sql = "SELECT * FROM {$this->table}";
if ($this->where) {
- $sql .= " WHERE " . implode(' AND ', $this->where);
+ $sql .= " WHERE {$this->where}";
}
if ($this->order) {
$sql .= " OFFSET {$this->offset}";
}
- $paramsStr = json_encode($this->params);
- rou_alert(0,"class PROBE sql=<$sql>, params=<$paramsStr>");
- $stmt = $this->db->Select($sql,$this->params);
+ $stmt = $this->db->Select($sql);
return $stmt->fetchAll();
}
$sql = "SELECT COUNT(*) AS cnt FROM {$this->table}";
if ($this->where) {
- $sql .= " WHERE " . implode(' AND ', $this->where);
+ $sql .= " WHERE {$this->where}";
}
- $stmt = $this->db->Select($sql, $this->params);
+ $stmt = $this->db->Select($sql);
$row = $stmt->fetch();
return (int) $row['cnt'];
}
$rqst=NEW probe("emails",$limit,$offset);
if (isset($_POST['username'])) {
$username=trim(($_POST['username']));
- $rqst->where("email","like","%$username%");
- }
+ $rqst->where("email like '%$username%'");
+}
$numrec=$rqst->getnumrec();
if (isset($_POST['scanner'])) {
$scanner=$_POST['scanner'];
default :
break;
}
- }
+}
$emails=$rqst->order("email asc")
->limit($limit)
->get();