setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch (PDOException $ex) { die("Connection failed: " . $ex->getMessage()); } } return self::$pdoInstance; } public static function query($query, $params = array(), $useCache = false) { if ($useCache && isset(self::$cache[$query])) { return self::$cache[$query]; } $statement = self::connect()->prepare($query); try { $statement->execute($params); if (explode(' ', $query)[0] === 'SELECT' || explode(' ', $query)[0] === 'SHOW' || explode(' ', $query)[0] === 'DESCRIBE') { $data = $statement->fetchAll(PDO::FETCH_ASSOC); if ($useCache) { self::$cache[$query] = $data; } return $data; } } catch (PDOException $ex) { die("Query failed: " . $ex->getMessage()); } } } ?>