From f5e972c030675f46cda543e13da1b787457e070b Mon Sep 17 00:00:00 2001 From: cflip <36554078+cflip@users.noreply.github.com> Date: Wed, 23 Jun 2021 15:21:12 -0600 Subject: Add the rest of the changes --- includes/Database.php | 162 +++++++++++++++++++++++++------------------------- 1 file changed, 81 insertions(+), 81 deletions(-) mode change 100644 => 100755 includes/Database.php (limited to 'includes/Database.php') diff --git a/includes/Database.php b/includes/Database.php old mode 100644 new mode 100755 index 0a79dfb..61fbbb1 --- a/includes/Database.php +++ b/includes/Database.php @@ -1,82 +1,82 @@ -sql_connection = mysqli_connect($db_server, $db_user, $db_pass, $db_database); - - if (!$this->sql_connection) { - trigger_error("Database connection error: " . mysqli_connect_error()); - } - } - - public static function get() - { - if (self::$instance == null) { - self::$instance = new Database(); - } - - return self::$instance; - } - - public function query(string $sql, string $types = "", ...$vars): array - { - $result = array(); - - if ($types == "") { - // No types were provided, preparing a statement is not necessary - $db_result = mysqli_query($this->sql_connection, $sql); - } else { - $stmt = mysqli_stmt_init($this->sql_connection); - - if (!mysqli_stmt_prepare($stmt, $sql)) { - trigger_error('Internal error: ' . mysqli_error($this->sql_connection)); - return $result; - } - - mysqli_stmt_bind_param($stmt, $types, ...$vars); - mysqli_stmt_execute($stmt); - - $db_result = mysqli_stmt_get_result($stmt); - - mysqli_stmt_close($stmt); - } - - if (!$db_result) { - return $result; - } - - if (mysqli_num_rows($db_result) > 0) { - while ($row = mysqli_fetch_assoc($db_result)) { - array_push($result, $row); - } - } - - mysqli_free_result($db_result); - - return $result; - } - - /** - * Returns the auto generated ID of the last query. - * This function is just a wrapper for mysqli_insert_id. - * In the future, it might be better to return different - * values in the query function depending on the type of - * SQL query. - */ - public function get_last_id() - { - return mysqli_insert_id($this->sql_connection); - } +sql_connection = mysqli_connect($db_server, $db_user, $db_pass, $db_database); + + if (!$this->sql_connection) { + trigger_error("Database connection error: " . mysqli_connect_error()); + } + } + + public static function get() + { + if (self::$instance == null) { + self::$instance = new Database(); + } + + return self::$instance; + } + + public function query(string $sql, string $types = "", ...$vars): array + { + $result = array(); + + if ($types == "") { + // No types were provided, preparing a statement is not necessary + $db_result = mysqli_query($this->sql_connection, $sql); + } else { + $stmt = mysqli_stmt_init($this->sql_connection); + + if (!mysqli_stmt_prepare($stmt, $sql)) { + trigger_error('Internal error: ' . mysqli_error($this->sql_connection)); + return $result; + } + + mysqli_stmt_bind_param($stmt, $types, ...$vars); + mysqli_stmt_execute($stmt); + + $db_result = mysqli_stmt_get_result($stmt); + + mysqli_stmt_close($stmt); + } + + if (!$db_result) { + return $result; + } + + if (mysqli_num_rows($db_result) > 0) { + while ($row = mysqli_fetch_assoc($db_result)) { + array_push($result, $row); + } + } + + mysqli_free_result($db_result); + + return $result; + } + + /** + * Returns the auto generated ID of the last query. + * This function is just a wrapper for mysqli_insert_id. + * In the future, it might be better to return different + * values in the query function depending on the type of + * SQL query. + */ + public function get_last_id() + { + return mysqli_insert_id($this->sql_connection); + } } \ No newline at end of file -- cgit v1.2.3