6c102c3855852b61e7b1a986843dc4f22e2fd2e4
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 $connection = new mysqli($host, $username, $password, $dbname);
24 $this->connection
= $connection;
26 if (!$this->connection
->connect_errno
) {
27 $this->connected
= true;
29 die('Fail to connect to the RDBMS.');
32 return $this->connection
;
35 /* public function __destruct()
42 * @return [type] [description]
44 public function close()
46 if ($this->connected
&& $this->connection
->close()) {
47 $this->connected
= false;
49 die('Fail to close the connection to the RDBMS.');
55 * @param [type] $sql_query [description]
56 * @return [type] [description]
58 public function query($sql_query)
60 if ($this->connected
&& !($this->current_result
= $this->connection
->query($sql_query))) {
61 echo "Fail to execute the SQL query : " . $sql_query . "<br>";
63 return $this->current_result
;
67 * [prepare_query description]
68 * @param [type] $prepared_query [description]
69 * @return [type] [description]
71 public function prepare_query($prepared_query)
73 $this->current_pquery
= $prepared_query;
74 if ($this->connected
&& !($this->current_stmt
= $this->connection
->prepare($this->current_pquery
))) {
75 // Empty the currently stored prepared query in the failure case
76 $this->current_pquery
= "";
77 echo "Fail to prepare SQL query : (" . $this->connection
->errno
. ") " . $this->connection
->error
. " - " . $this->current_pquery
. "<br>";
79 return $this->current_stmt
;
83 * [prepared_query_bind_param description]
84 * @param [type] $params [description]
85 * @return [type] [description]
87 public function prepared_query_bind_param($types, $params)
89 $rt_val = $this->current_stmt
->bind_param($types, ...$params);
91 echo "Fail to link parameters to SQL query : (" . $this->current_stmt
->errno
. ") " . $this->current_stmt
->error
. " - " . $this->current_pquery
. "<br>";
97 * [run_prepared_query description]
98 * @return [type] [description]
100 public function run_prepared_query()
102 $rt_val = $this->current_stmt
->execute();
104 echo "Fail to execute SQL query : (" . $this->current_stmt
->errno
. ") " . $this->current_stmt
->error
. " - " . $this->current_pquery
. "<br>";
109 public function get_pquery_result()
111 $rt_val = $this->current_result
= $this->current_stmt
->get_result();
113 echo "Fail to fill SQL query result : (" . $this->current_stmt
->errno
. ") " . $this->current_stmt
->error
. " - " . $this->current_pquery
. "<br>";
118 public function get_result_array()
120 $rt_val = $this->current_result
->fetch_array();
122 echo "Fail to build SQL query result array : (" . $this->current_stmt
->errno
. ") " . $this->current_stmt
->error
. " - " . $this->current_pquery
. "<br>";
128 * [close_prepared_query description]
129 * @return [type] [description]
131 public function close_prepared_query()
133 $rt_val = $this->current_stmt
->close();
135 echo "Fail to close SQL query : (" . $this->current_stmt
->errno
. ") " . $this->current_stmt
->error
. " - " . $this->current_pquery
. "<br>";