4 * [CustomDB description]
10 private $current_pquery;
11 private $current_stmt;
14 * [__construct description]
15 * @param [type] $host [description]
16 * @param [type] $username [description]
17 * @param [type] $password [description]
18 * @param [type] $dbname [description]
20 public function __construct($host, $username, $password, $dbname)
22 $connection = new mysqli($host, $username, $password, $dbname);
23 $this->connection
= $connection;
25 if (!$this->connection
->connect_errno
) {
26 $this->connected
= true;
28 die('Fail to connect to the RDBMS');
31 return $this->connection
;
36 * @return [type] [description]
38 public function close()
40 if ($this->connected
&& $this->connection
->close()) {
41 $this->connected
= false;
43 die('Fail to close the connection to the RDBMS');
49 * @param [type] $sql_query [description]
50 * @return [type] [description]
52 public function query($sql_query)
54 if ($this->connected
&& !($query_result = $this->connection
->query($sql_query))) {
55 echo "Fail to execute the SQL query : " . $sql_query;
61 * [prepare_query description]
62 * @param [type] $prepared_query [description]
63 * @return [type] [description]
65 public function prepare_query($prepared_query)
67 $this->current_pquery
= $prepared_query;
68 if ($this->connected
&& !($this->current_stmt
= $this->connection
->prepare($this->current_pquery
))) {
69 // Empty the currently stored prepared query in the failure case
70 $this->current_pquery
= "";
71 echo "Fail to prepare SQL query : (" . $this->connection
->errno
. ") " . $this->connection
->error
. " - " . $this->current_pquery
;
73 return $this->current_stmt
;
77 * [prepared_query_bind_param description]
78 * @param [type] $params [description]
79 * @return [type] [description]
81 public function prepared_query_bind_param(...$params)
83 $rt_val = $this->current_stmt
->bind_param($params);
85 echo "Fail to link parameters to SQL query : (" . $this->current_stmt
->errno
. ") " . $this->current_stmt
->error
. " - " . $this->current_pquery
;
91 * [run_prepared_query description]
92 * @return [type] [description]
94 public function run_prepared_query()
96 $rt_val = $this->current_stmt
->execute();
98 echo "Fail to execute SQL query : (" . $this->current_stmt
->errno
. ") " . $this->current_stmt
->error
. " - " . $this->current_pquery
;
104 * [close_prepared_query description]
105 * @return [type] [description]
107 public function close_prepared_query()
109 $rt_val = $this->current_stmt
->close();
111 echo "Fail to close SQL query : (" . $this->current_stmt
->errno
. ") " . $this->current_stmt
->error
. " - " . $this->current_pquery
;