4 * [CustomDB description]
10 private $current_pquery;
11 private $current_stmt;
12 private $current_result;
15 * [__construct description]
16 * @param [type] $host [description]
17 * @param [type] $username [description]
18 * @param [type] $password [description]
19 * @param [type] $dbname [description]
21 public function __construct($host, $username, $password, $dbname)
23 $this->connection
= new mysqli($host, $username, $password, $dbname);
25 if (!$this->connection
->connect_errno
) {
26 $this->connected
= true;
28 die('Fail to connect to the RDBMS.');
31 return $this->connection
;
35 * [__destruct description]
37 /* public function __destruct()
44 * @return [type] [description]
46 public function close()
48 if ($this->connected
&& $this->connection
->close()) {
49 $this->connected
= false;
51 die('Fail to close the connection to the RDBMS.');
57 * @param [type] $sql_query [description]
58 * @return [type] [description]
60 public function query($sql_query)
62 if ($this->connected
&& !($this->current_result
= $this->connection
->query($sql_query))) {
63 echo "Fail to execute the SQL query : " . $sql_query . "<br>";
65 return $this->current_result
;
69 * [prepare_query description]
70 * @param [type] $prepared_query [description]
71 * @return [type] [description]
73 public function prepare_query($prepared_query)
75 $this->current_pquery
= $prepared_query;
76 if ($this->connected
&& !($this->current_stmt
= $this->connection
->prepare($this->current_pquery
))) {
77 // Empty the currently stored prepared query in the failure case
78 $this->current_pquery
= "";
79 echo "Fail to prepare SQL query : (" . $this->connection
->errno
. ") " . $this->connection
->error
. " - " . $this->current_pquery
. "<br>";
81 return $this->current_stmt
;
85 * [prepared_query_bind_param description]
86 * @param [type] $types [description]
87 * @param [type] $params [description]
88 * @return [type] [description]
90 public function prepared_query_bind_param($types, $params)
92 $rt_val = $this->current_stmt
->bind_param($types, ...$params);
94 echo "Fail to link parameters to SQL query : (" . $this->current_stmt
->errno
. ") " . $this->current_stmt
->error
. " - " . $this->current_pquery
. "<br>";
100 * [run_prepared_query description]
101 * @return [type] [description]
103 public function run_prepared_query()
105 $rt_val = $this->current_stmt
->execute();
107 echo "Fail to execute SQL query : (" . $this->current_stmt
->errno
. ") " . $this->current_stmt
->error
. " - " . $this->current_pquery
. "<br>";
113 * [get_pquery_result description]
114 * @return [type] [description]
116 public function get_pquery_result()
118 $rt_val = $this->current_result
= $this->current_stmt
->get_result();
120 echo "Fail to fill SQL query result : (" . $this->current_stmt
->errno
. ") " . $this->current_stmt
->error
. " - " . $this->current_pquery
. "<br>";
126 * [get_result_array description]
127 * @return [type] [description]
129 public function get_result_array()
131 $row = $this->current_result
->fetch_array();
134 } elseif (!isset($row)) {
135 echo "Fail to build SQL query result array : (" . $this->current_stmt
->errno
. ") " . $this->current_stmt
->error
. " - " . $this->current_pquery
. "<br>";
139 while ($row = $this->current_result
->fetch_array()) {
148 * [close_prepared_query description]
149 * @return [type] [description]
151 public function close_prepared_query()
153 $rt_val = $this->current_stmt
->close();
155 echo "Fail to close SQL query : (" . $this->current_stmt
->errno
. ") " . $this->current_stmt
->error
. " - " . $this->current_pquery
. "<br>";