File "diagnostico.php"

Full Path: C:/wamp64/www/Formaciones/diagnostico.php
File size: 3.93 KB
MIME-type: text/x-php
Charset: utf-8

<?php
// diagnostico_formacion.php
// Coloca este archivo en la raíz de tu proyecto y accédelo desde el navegador

require_once 'Configuracion/db.php';

echo "<h1>Diagnóstico del Módulo Formación</h1>";

// 1. Verificar estructura de la tabla
echo "<h2>1. Estructura de la tabla 'formacion'</h2>";
$result = $mysqli->query("DESCRIBE formacion");
echo "<table border='1' cellpadding='5'>";
echo "<tr><th>Campo</th><th>Tipo</th><th>Null</th><th>Key</th><th>Default</th></tr>";
while ($row = $result->fetch_assoc()) {
    echo "<tr>";
    echo "<td>{$row['Field']}</td>";
    echo "<td>{$row['Type']}</td>";
    echo "<td>{$row['Null']}</td>";
    echo "<td>{$row['Key']}</td>";
    echo "<td>{$row['Default']}</td>";
    echo "</tr>";
}
echo "</table>";

// 2. Verificar archivos del modelo
echo "<h2>2. Verificar archivo FormacionModelo.php</h2>";
$modelo_path = __DIR__ . '/Modelos/FormacionModelo.php';
if (file_exists($modelo_path)) {
    echo "✅ Archivo existe<br>";
    echo "📅 Última modificación: " . date("Y-m-d H:i:s", filemtime($modelo_path)) . "<br>";
    
    // Leer el contenido del método guardar
    $contenido = file_get_contents($modelo_path);
    if (strpos($contenido, 'tipo_formacion') !== false) {
        echo "✅ El archivo CONTIENE 'tipo_formacion'<br>";
    } else {
        echo "❌ El archivo NO CONTIENE 'tipo_formacion'<br>";
    }
    
    // Verificar el bind_param
    preg_match('/bind_param\s*\(\s*"([^"]+)"/', $contenido, $matches);
    if ($matches) {
        echo "📝 Patrón bind_param actual: <strong>{$matches[1]}</strong><br>";
        echo "✅ Debería ser: <strong>ssssssssbs</strong> (9 strings + 1 blob)<br>";
    }
} else {
    echo "❌ Archivo NO existe en: $modelo_path<br>";
}

// 3. Verificar archivo del controlador
echo "<h2>3. Verificar archivo FormacionControlador.php</h2>";
$controlador_path = __DIR__ . '/Controladores/FormacionControlador.php';
if (file_exists($controlador_path)) {
    echo "✅ Archivo existe<br>";
    echo "📅 Última modificación: " . date("Y-m-d H:i:s", filemtime($controlador_path)) . "<br>";
    
    $contenido = file_get_contents($controlador_path);
    
    // Contar cuántos parámetros pasa al modelo->guardar()
    if (preg_match('/\$this->modelo->guardar\s*\((.*?)\)/s', $contenido, $matches)) {
        $params = explode(',', $matches[1]);
        $num_params = count($params);
        echo "📝 Número de parámetros pasados a modelo->guardar(): <strong>$num_params</strong><br>";
        echo "✅ Debería ser: <strong>10</strong><br>";
        
        if ($num_params == 10) {
            echo "✅ <span style='color:green'>CORRECTO: Se pasan 10 parámetros</span><br>";
        } else {
            echo "❌ <span style='color:red'>ERROR: Se pasan $num_params parámetros en lugar de 10</span><br>";
        }
    }
} else {
    echo "❌ Archivo NO existe en: $controlador_path<br>";
}

// 4. Test de INSERT (sin ejecutar)
echo "<h2>4. SQL que debería ejecutarse</h2>";
echo "<pre>";
echo "INSERT INTO formacion (
    area, 
    tipo_formacion, 
    cedula_usuario, 
    capacitador, 
    cargoCap, 
    fecha_Inicial, 
    fecha_Final, 
    temas, 
    evidencia_datos, 
    namePro, 
    created_at
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, NOW())";
echo "</pre>";

echo "<h2>✅ Checklist de solución</h2>";
echo "<ol>";
echo "<li>¿La tabla tiene la columna 'tipo_formacion'? Verificar arriba</li>";
echo "<li>¿El FormacionModelo.php está actualizado? Verificar fecha de modificación</li>";
echo "<li>¿El FormacionControlador.php pasa 10 parámetros? Verificar arriba</li>";
echo "<li>¿El bind_param tiene 'ssssssssbs'? Verificar arriba</li>";
echo "</ol>";

echo "<hr>";
echo "<p><strong>Próximos pasos:</strong></p>";
echo "<ul>";
echo "<li>Si los archivos NO están actualizados, reemplázalos con las versiones corregidas</li>";
echo "<li>Si los archivos SÍ están actualizados pero el error persiste, verifica que no haya caché de PHP (reinicia Apache/Nginx)</li>";
echo "</ul>";
?>