public function query($consulta, $valores = array(), $cache = TRUE) { $resultado = FALSE; $query = $consulta; $cache = APP_CACHE; if (APP_CACHE) { if (strstr(strtoupper(trim($query)), "__SESIONES")) { $cache = FALSE; } } if ($statement = self::$conexion->prepare($consulta)) { if (preg_match_all("/(:\\w+)/", $consulta, $campo, PREG_PATTERN_ORDER)) { $campo = array_pop($campo); foreach ($campo as $parametro) { $statement->bindValue($parametro, $valores[substr($parametro, 1)]); $query = str_replace($parametro, $valores[substr($parametro, 1)], $query); } } if ($cache) { $cached = Sfphp_Cache::get("data_" . md5($query)); if ($cached) { return $cached; } } try { if (!$statement->execute()) { throw new PDOException("[SQLSTATE] " . $statement->errorInfo()[2], $statement->errorInfo()[1]); } $resultado = $statement->fetchAll(PDO::FETCH_ASSOC); $statement->closeCursor(); } catch (PDOException $e) { trigger_error($e->getMessage(), E_USER_ERROR); } if ($cache) { Sfphp_Cache::set("data_" . md5($query), $resultado); } if (DEV_QUERYLOG) { Sfphp_Log::query($query); } return $resultado; } }