private function executeQuery($query, $type = self::FETCH_ASSOC, $database = null)
 {
     $conn = new Database();
     if ($database != null) {
         $conn->changeDatabase($database);
     }
     $mysqli = $conn->getConnection();
     //array che conterrà il risultato da restituire
     $arrOutput = array();
     //echo "Query: $query <br>";
     //echo "Type: $type <br>";
     if (!($result = $mysqli->query($query))) {
         $err = $query . " errore: " . $mysqli->error;
         $mysqli->close();
         return $err;
     }
     if ($result->num_rows > 0) {
         if ($type == self::FETCH_ROW) {
             while ($row = $result->fetch_row()) {
                 array_push($arrOutput, $row);
             }
         }
         if ($type == self::FETCH_ASSOC) {
             while ($row = $result->fetch_assoc()) {
                 array_push($arrOutput, $row);
             }
         }
     } else {
         if ($type == self::FETCH_FIELDS) {
             $row = $result->fetch_fields();
             $arrOutput = $row;
         } else {
             $result->close();
             $mysqli->close();
             return 0;
         }
     }
     $result->close();
     $mysqli->close();
     unset($conn);
     return $arrOutput;
 }