noalyss-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Noalyss-commit] [noalyss] 08/16: Improve Code: Database : add __toStrin


From: dwm
Subject: [Noalyss-commit] [noalyss] 08/16: Improve Code: Database : add __toString
Date: Tue, 27 May 2025 09:26:08 -0400 (EDT)

sparkyx pushed a commit to branch unstable
in repository noalyss.

commit 001677eb7230c24cc8ac5f3ee2a80902e2c7082a
Author: sparkyx <danydb@noalyss.eu>
AuthorDate: Mon May 19 23:01:31 2025 +0200

    Improve Code:  Database  : add __toString
---
 include/class/database.class.php    | 13 +++++++++++--
 include/lib/database_core.class.php | 33 ++++++++++++++++++++++++++++-----
 2 files changed, 39 insertions(+), 7 deletions(-)

diff --git a/include/class/database.class.php b/include/class/database.class.php
index 22865788a..38a8e0daf 100644
--- a/include/class/database.class.php
+++ b/include/class/database.class.php
@@ -69,9 +69,18 @@ class Database extends DatabaseCore
             $this->exec_sql('set search_path to 
public,comptaproc,pg_catalog;');
         }
         $this->exec_sql('set DateStyle to ISO, MDY;');
-
+        $this->ret=true;
+        $this->is_open=true;
     }
-
+    function __toString(): string {
+        return "DatabaseCore[db=" . var_export($this->db,true)
+            . ", ret=" .var_export( $this->ret,true)
+            . ", is_open=" . $this->is_open
+            . ", sql=" . $this->sql
+            . ", array=" . var_export($this->array,true)
+            . ",dbname = ".$this->get_dbname()
+            . "]";
+}
     /***
      * \brief Save a "piece justificative" , the name must be pj
      *
diff --git a/include/lib/database_core.class.php 
b/include/lib/database_core.class.php
index 1a9ba6efc..04602f3ff 100644
--- a/include/lib/database_core.class.php
+++ b/include/lib/database_core.class.php
@@ -37,12 +37,17 @@ class DatabaseCore
 
     protected $db;
     /**< database connection */
-    private $ret;
+    protected $ret;
     /**< return value  */
-    private $is_open;                   /*!< true is connected */
+    protected $is_open;                   /*!< true is connected */
     public $sql;     //!< last SQL stmt executed
     public $array;
-    /*** Connect to a database return an connx to db or false if it fails
+    protected $dbname; ///!< $dbname (string) Database name
+    protected $dbport;///!< $dbport (int) Database port
+    protected $dbhost;///!< $dbhost(string) Database host
+    protected $dbuser;///!< $dbuser(string) Database user
+    /*** 
+     * @brief Connect to a database return an connx to db or false if it fails
      *
      * @param string $p_user Username
      * @param type $p_password User's password
@@ -74,13 +79,31 @@ class DatabaseCore
                 throw new Exception(_('Erreur Connexion'));
             }
         }
-
+        $this->dbport=$p_port;
+        $this->dbname=$p_dbname;
+        $this->dbhost=$p_host;
+        $this->dbuser=$p_user;
         $this->is_open = TRUE;
         $this->sql="";
 
     }
+    public function get_dbname() {
+        return $this->dbname;
+    }
 
-    /**
+    public function get_dbport() {
+        return $this->dbport;
+    }
+
+    public function get_dbhost() {
+        return $this->dbhost;
+    }
+
+    public function get_dbuser() {
+        return $this->dbuser;
+    }
+
+        /**
      * return the name of the current database
      * @return false|string
      */



reply via email to

[Prev in Thread] Current Thread [Next in Thread]