<?php
ini_set('display_errors', '1');
error_reporting(E_ALL);
require_once dirname(__FILE__) . '/../config.php';

$db = getDB();

// Ver estructura de la tabla productos
echo "=== COLUMNAS DE productos ===\n";
$s = $db->query('DESCRIBE productos');
foreach ($s->fetchAll() as $col) {
    echo $col['Field'] . " (" . $col['Type'] . ") default=" . $col['Default'] . "\n";
}

echo "\n=== TOTAL PRODUCTOS ===\n";
$s = $db->query('SELECT COUNT(*) as c FROM productos');
echo "Total: " . $s->fetch()['c'] . "\n";

echo "\n=== VALORES DISTINTOS DE puv ===\n";
$s = $db->query('SELECT puv, COUNT(*) as c FROM productos GROUP BY puv');
foreach ($s->fetchAll() as $r) {
    echo "puv=" . var_export($r['puv'], true) . " -> " . $r['c'] . " registros\n";
}

echo "\n=== PRIMEROS 3 PRODUCTOS ===\n";
$s = $db->query('SELECT id_prod, nombreProd, puv, tipoprod FROM productos LIMIT 3');
foreach ($s->fetchAll() as $r) {
    echo json_encode($r) . "\n";
}
