$conn->set_charset('utf8mb4');
// Función para fecha relativa
function fechaRelativa($fecha) {
    try {
        $ahora = new DateTime();
        $fecha_pub = new DateTime($fecha);
        $diferencia = $ahora->diff($fecha_pub);
        
        if ($diferencia->y > 0) {
            return "hace " . $diferencia->y . " año" . ($diferencia->y > 1 ? "s" : "");
        } elseif ($diferencia->m > 0) {
            return "hace " . $diferencia->m . " mes" . ($diferencia->m > 1 ? "es" : "");
        } elseif ($diferencia->d > 0) {
            if ($diferencia->d == 1) return "ayer";
            return "hace " . $diferencia->d . " días";
        } elseif ($diferencia->h > 0) {
            return "hace " . $diferencia->h . " hora" . ($diferencia->h > 1 ? "s" : "");
        } elseif ($diferencia->i > 0) {
            return "hace " . $diferencia->i . " minuto" . ($diferencia->i > 1 ? "s" : "");
        } else {
            return "ahora mismo";
        }
    } catch (Exception $e) {
        return "fecha desconocida";
    }
}
// Función para verificar y mostrar imágenes
function obtenerImagenArticulo($imagen, $titulo) {
    $uploads_path = __DIR__ . '/../uploads/';
    $web_path = './uploads/';
    
    if (!empty($imagen)) {
        $image_path = $uploads_path . $imagen;
        if (file_exists($image_path)) {
            return [
                'tipo' => 'real',
                'src' => $web_path . $imagen,
                'alt' => htmlspecialchars($titulo)
            ];
        }
    }
    
    // Generar placeholder
    $colors = ['#f8f9fa', '#e9ecef', '#dee2e6', '#ced4da', '#adb5bd'];
    $color = $colors[crc32($titulo) % count($colors)];
    
    $svg = '
             
            
            '.mb_substr(htmlspecialchars($titulo), 0, 30).(mb_strlen($titulo) > 30 ? '...' : '').' 
            
            Imagen no disponible 
             ';
    
    return [
        'tipo' => 'placeholder',
        'src' => 'data:image/svg+xml;base64,' . base64_encode($svg),
        'alt' => 'Placeholder: ' . htmlspecialchars($titulo)
    ];
}
?> 
Warning :  Undefined variable $conn in /www/cognitytech/mdscontenidos.store/public/ver_articulo.php  on line 4  
 
Fatal error :  Uncaught Error: Call to a member function prepare() on null in /www/cognitytech/mdscontenidos.store/public/ver_articulo.php:4
Stack trace:
#0 {main}
  thrown in /www/cognitytech/mdscontenidos.store/public/ver_articulo.php  on line 4