Improve Code: Database : add __toString

This commit is contained in:
sparkyx 2025-05-19 23:01:31 +02:00
parent da1a6dbc39
commit 001677eb72
2 changed files with 39 additions and 7 deletions

View file

@ -69,9 +69,18 @@ class Database extends DatabaseCore
$this->exec_sql('set search_path to public,comptaproc,pg_catalog;'); $this->exec_sql('set search_path to public,comptaproc,pg_catalog;');
} }
$this->exec_sql('set DateStyle to ISO, MDY;'); $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 * \brief Save a "piece justificative" , the name must be pj
* *

View file

@ -37,12 +37,17 @@ class DatabaseCore
protected $db; protected $db;
/**< database connection */ /**< database connection */
private $ret; protected $ret;
/**< return value */ /**< return value */
private $is_open; /*!< true is connected */ protected $is_open; /*!< true is connected */
public $sql; //!< last SQL stmt executed public $sql; //!< last SQL stmt executed
public $array; 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 string $p_user Username
* @param type $p_password User's password * @param type $p_password User's password
@ -74,13 +79,31 @@ class DatabaseCore
throw new Exception(_('Erreur Connexion')); 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->is_open = TRUE;
$this->sql=""; $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 the name of the current database
* @return false|string * @return false|string
*/ */