bind_param($types, ...$params); } // Execute an SQL query with a prepared statement private function run_query(string $sql, mixed $params = null): mysqli_result|bool { $stmt = $this->prepare($sql); // Bind parameters if provided if ($params !== null) { $this->bind_params($stmt, $params); } // Execute statement and get retrieve changes $query = $stmt->execute(); $res = $stmt->get_result(); // Return true if an INSERT, UPDATE or DELETE was sucessful (no rows returned) if (!empty($query) && empty($res)) { return true; } // Return mysqli_result object return $res; } /* ---- */ // Execute SQL query with optional prepared statement and return array of affected rows public function exec(string $sql, mixed $params = null): array { $query = $this->run_query($sql, $params); $res = []; // Fetch rows into sequential array while ($row = $query->fetch_assoc()) { $res[] = $row; } return $res; } // Execute SQL query with optional prepared statement and return true if query was successful public function exec_bool(string $sql, mixed $params = null): bool { $query = $this->run_query($sql, $params); return gettype($query) === "boolean" // Type is already a bool, so return it as is ? $query // Return true if rows were matched : $query->num_rows > 0; } }