setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $stmt = $conn_translate->prepare("SELECT setting FROM config WHERE id = 1"); $stmt->execute(); $result = $stmt->fetch(PDO::FETCH_ASSOC); $new_dbname = $result['setting']; if ($new_dbname !== $dbname) { $dbname = $new_dbname; $conn_translate = new PDO("mysql:host=$servername;dbname=$dbname;charset=utf8mb4", $username, $password); $conn_translate->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } } catch (PDOException $e) { echo "Error de conexión: " . $e->getMessage(); } } if (!isset($db_textos)) { $db_textos = array(); } if (!isset($db_imagenes)) { $db_imagenes = array(); } if (!isset($db_enlaces)) { $db_enlaces = array(); } function init_page_60($pagina) { global $conn_translate; global $idioma; global $db_textos; global $db_imagenes; global $db_enlaces; $query = "SELECT t.id, tt.contenido FROM textos t INNER JOIN textos_traducciones tt ON t.id = tt.texto WHERE t.pagina = :arg1 AND tt.idioma = :arg2"; $stmt = $conn_translate->prepare($query); $stmt->bindParam(":arg1", $pagina); $stmt->bindParam(":arg2", $idioma); $stmt->execute(); $results = $stmt->fetchAll(PDO::FETCH_ASSOC); foreach($results as $row) { $db_textos[intval($row['id'])] = $row['contenido']; } $query = "SELECT DISTINCT it.imagen, CONCAT((SELECT setting FROM config WHERE id = 2), it.idioma, it.src) AS src, it.title FROM pagina_relaciones pr INNER JOIN imagenes_traducciones it ON pr.identificador = it.imagen WHERE pr.pagina = :arg1 AND it.idioma = :arg2 AND pr.tabla = 'imagenes'"; $stmt = $conn_translate->prepare($query); $stmt->bindParam(":arg1", $pagina); $stmt->bindParam(":arg2", $idioma); $stmt->execute(); $results = $stmt->fetchAll(PDO::FETCH_ASSOC); foreach($results as $row) { $db_imagenes[intval($row['imagen'])] = array("src" => $row['src'], "title" => $row['title']); } $query = "SELECT DISTINCT et.enlace, CONCAT((SELECT setting FROM config WHERE id = 2), et.idioma, et.href) AS href FROM pagina_relaciones pr INNER JOIN enlaces_traducciones et ON pr.identificador = et.enlace WHERE pr.pagina = :arg1 AND et.idioma = :arg2 AND pr.tabla = 'enlaces'"; $stmt = $conn_translate->prepare($query); $stmt->bindParam(":arg1", $pagina); $stmt->bindParam(":arg2", $idioma); $stmt->execute(); $results = $stmt->fetchAll(PDO::FETCH_ASSOC); foreach($results as $row) { $href = $row['href']; $posicion_punto = strrpos($href, "."); if ($posicion_punto !== false) { $href = substr($href, 0, $posicion_punto); } $db_enlaces[intval($row['enlace'])] = $href; } } init_page_60(60); if (!function_exists("get_img")) { function get_img($id, $type) { global $db_imagenes; return $db_imagenes[$id][$type]; } } if (!function_exists("get_link")) { function get_link($id) { global $db_enlaces; return $db_enlaces[$id]; } } if (!function_exists("get_tag")) { function get_tag($id) { global $db_textos; return $db_textos[$id]; } } ?>