X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=lib%2Fdb.php;h=6c102c3855852b61e7b1a986843dc4f22e2fd2e4;hb=a96fefe119b8c91c2f5ae6ad04e11af676e5540b;hp=0f280a459e8efbdbeb55c0de5730481678b6cf9b;hpb=6405835a808d5ac4986ff463a7be0b146058440d;p=Project_webapp.git diff --git a/lib/db.php b/lib/db.php index 0f280a4..6c102c3 100644 --- a/lib/db.php +++ b/lib/db.php @@ -9,6 +9,7 @@ class CustomDB public $connected; private $current_pquery; private $current_stmt; + private $current_result; /** * [__construct description] @@ -25,12 +26,17 @@ class CustomDB if (!$this->connection->connect_errno) { $this->connected = true; } else { - die('Fail to connect to the RDBMS'); + die('Fail to connect to the RDBMS.'); } return $this->connection; } + /* public function __destruct() + { + $this->close(); + } */ + /** * [close description] * @return [type] [description] @@ -40,7 +46,7 @@ class CustomDB if ($this->connected && $this->connection->close()) { $this->connected = false; } else { - die('Fail to close the connection to the RDBMS'); + die('Fail to close the connection to the RDBMS.'); } } @@ -51,10 +57,10 @@ class CustomDB */ public function query($sql_query) { - if ($this->connected && !($query_result = $this->connection->query($sql_query))) { - echo "Fail to execute the SQL query : " . $sql_query; + if ($this->connected && !($this->current_result = $this->connection->query($sql_query))) { + echo "Fail to execute the SQL query : " . $sql_query . "
"; } - return $query_result; + return $this->current_result; } /** @@ -68,7 +74,7 @@ class CustomDB if ($this->connected && !($this->current_stmt = $this->connection->prepare($this->current_pquery))) { // Empty the currently stored prepared query in the failure case $this->current_pquery = ""; - echo "Fail to prepare SQL query : (" . $this->connection->errno . ") " . $this->connection->error . " - " . $this->current_pquery; + echo "Fail to prepare SQL query : (" . $this->connection->errno . ") " . $this->connection->error . " - " . $this->current_pquery . "
"; } return $this->current_stmt; } @@ -78,11 +84,11 @@ class CustomDB * @param [type] $params [description] * @return [type] [description] */ - public function prepared_query_bind_param(...$params) + public function prepared_query_bind_param($types, $params) { - $rt_val = $this->current_stmt->bind_param($params); + $rt_val = $this->current_stmt->bind_param($types, ...$params); if (!$rt_val) { - echo "Fail to link parameters to SQL query : (" . $this->current_stmt->errno . ") " . $this->current_stmt->error . " - " . $this->current_pquery; + echo "Fail to link parameters to SQL query : (" . $this->current_stmt->errno . ") " . $this->current_stmt->error . " - " . $this->current_pquery . "
"; } return $rt_val; } @@ -95,7 +101,25 @@ class CustomDB { $rt_val = $this->current_stmt->execute(); if (!$rt_val) { - echo "Fail to execute SQL query : (" . $this->current_stmt->errno . ") " . $this->current_stmt->error . " - " . $this->current_pquery; + echo "Fail to execute SQL query : (" . $this->current_stmt->errno . ") " . $this->current_stmt->error . " - " . $this->current_pquery . "
"; + } + return $rt_val; + } + + public function get_pquery_result() + { + $rt_val = $this->current_result = $this->current_stmt->get_result(); + if (!$rt_val) { + echo "Fail to fill SQL query result : (" . $this->current_stmt->errno . ") " . $this->current_stmt->error . " - " . $this->current_pquery . "
"; + } + return $rt_val; + } + + public function get_result_array() + { + $rt_val = $this->current_result->fetch_array(); + if (!$rt_val) { + echo "Fail to build SQL query result array : (" . $this->current_stmt->errno . ") " . $this->current_stmt->error . " - " . $this->current_pquery . "
"; } return $rt_val; } @@ -108,7 +132,7 @@ class CustomDB { $rt_val = $this->current_stmt->close(); if (!$rt_val) { - echo "Fail to close SQL query : (" . $this->current_stmt->errno . ") " . $this->current_stmt->error . " - " . $this->current_pquery; + echo "Fail to close SQL query : (" . $this->current_stmt->errno . ") " . $this->current_stmt->error . " - " . $this->current_pquery . "
"; } return $rt_val; }