]> SAFE projects GIT repository - jmp/mailleur/commitdiff
New SQL function seems to be working
authorJean-Marc Pigeon <jmp@safe.c>
Tue, 25 Nov 2025 04:09:24 +0000 (23:09 -0500)
committerJean-Marc Pigeon <jmp@safe.c>
Tue, 25 Nov 2025 04:09:24 +0000 (23:09 -0500)
www/gessql.php
www/lvlusr.php

index 260b4b13f54626ce128b2aa9d1940050fb6fe32b..34b7d57495cb3f44f063ffff782a3ca4ecf1557d 100644 (file)
@@ -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'];
     }
index 9ef1cb683c6bfeffd5eccc2a6da921b03e7196a1..7028f25d56c768e164e069820f1f1be05dda85ff 100644 (file)
@@ -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();