From 55fe755952d82c324d8f73fb6ed28cec1e7ca3e6 Mon Sep 17 00:00:00 2001 From: Jean-Marc Pigeon Date: Mon, 24 Nov 2025 23:09:24 -0500 Subject: [PATCH] New SQL function seems to be working --- www/gessql.php | 29 ++++++++++++----------------- www/lvlusr.php | 6 +++--- 2 files changed, 15 insertions(+), 20 deletions(-) diff --git a/www/gessql.php b/www/gessql.php index 260b4b1..34b7d57 100644 --- a/www/gessql.php +++ b/www/gessql.php @@ -9,15 +9,14 @@ include_once "subrou.php"; 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 @@ -41,11 +40,9 @@ class probe { /** * 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; } @@ -75,7 +72,7 @@ class probe { $sql = "SELECT * FROM {$this->table}"; if ($this->where) { - $sql .= " WHERE " . implode(' AND ', $this->where); + $sql .= " WHERE {$this->where}"; } if ($this->order) { @@ -90,9 +87,7 @@ class probe { $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(); } @@ -104,10 +99,10 @@ class probe { $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']; } diff --git a/www/lvlusr.php b/www/lvlusr.php index 9ef1cb6..7028f25 100644 --- a/www/lvlusr.php +++ b/www/lvlusr.php @@ -96,8 +96,8 @@ if (isset($_POST['offset'])) $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']; @@ -117,7 +117,7 @@ if (isset($_POST['scanner'])) { default : break; } - } +} $emails=$rqst->order("email asc") ->limit($limit) ->get(); -- 2.47.3