<?php
ini_set('display_errors', 1);
header('Content-Type: application/json');
$pdo = new PDO('mysql:host=localhost;dbname=mikes5_rrb;charset=utf8', 'mikes5_rrb', 'Mikel123*');
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

// Estructura de promod
$cols = $pdo->query("DESCRIBE promod")->fetchAll(PDO::FETCH_ASSOC);
// Muestra de datos
$sample = $pdo->query("SELECT * FROM promod LIMIT 3")->fetchAll(PDO::FETCH_ASSOC);
// Rango de id_promo
$range = $pdo->query("SELECT MIN(id_promo) as min_id, MAX(id_promo) as max_id, COUNT(*) as total FROM promod")->fetch(PDO::FETCH_ASSOC);
// Muestra de nsalida con id_prod > 1000
$nsalida_promo = $pdo->query("SELECT * FROM nsalida WHERE productos_idprod > 1000 LIMIT 3")->fetchAll(PDO::FETCH_ASSOC);

echo json_encode([
    'columns' => $cols,
    'sample' => $sample,
    'range' => $range,
    'nsalida_promo_sample' => $nsalida_promo
], JSON_PRETTY_PRINT);
