File "smartphoneSelect.php"

Full Path: C:/wamp64/www/RegistroEquipos2/backend/telefono/smartphoneSelect.php
File size: 1.39 KB
MIME-type: text/x-php
Charset: utf-8

<?php
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST, OPTIONS');
header('Access-Control-Allow-Headers: Content-Type, Authorization');

$host = '192.200.100.40';
$db = 'sistemas';
$user = 'SANMARINO';
$pass = 'sanmarino2021*';
$charset = 'utf8mb4';

$dsn = "mysql:host=$host;dbname=$db;charset=$charset";

try {
    $pdo = new PDO($dsn, $user, $pass, [
        PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
    ]);
} catch (PDOException $e) {
    echo json_encode(['error' => 'Error de conexión: ' . $e->getMessage()]);
    exit();
}

header('Content-Type: application/json');

try {
    $sql = "SELECT 
                id,
                fecha,
                marca,
                referencia,
                color,   
                IMEI,
                numeroLinea,
                planDatos,
                operador,
                nombreRecibe,
                cedula,
                quienEntrega,
                observaciones,
                firma,
                imagen,
                
                cargoRecibe,
                imagen_2
            FROM registroSmartphones";

    $stmt = $pdo->query($sql);
    $registros = $stmt->fetchAll(PDO::FETCH_ASSOC);

    echo json_encode(['data' => $registros]);
} catch (PDOException $e) {
    echo json_encode([
        'data' => [],
        'error' => 'Error al listar registros: ' . $e->getMessage(),
    ]);
}
?>