ORA-01008: not all variables bound

2

I'm doing a query to a database using php, the case is that it gives me

  

error ORA-01008: not all variables bound

And I do not know how to solve it. If you can help me, I appreciate it. The function that I am executing is:

function consultarCitasOcupadas($conexion, $dia, $usuario) {
    $consulta = "SELECT HORA,DNI_PACIENTE,FECHA FROM CITAS"
        . " WHERE (FECHA = TO_DATE(:dia,'DD/MM/YYYY')"
        . " AND USUARIO_MEDICO=:usuario"
        . " AND DNI_PACIENTE IS NOT NULL)"
        . " ORDER BY HORA";
    return $conexion->query($consulta);
}
    
asked by Ray 21.08.2017 в 20:09
source

1 answer

2

What you need is to link the variables that you are including in your query. I like doing it with arrangements, because it seems a little simpler and more orderly.

$arreglo_variables = [
        'dia' => $dia,
        'usuario' => $usuario
];

So, by linking these variables, you can have your code this way

function consultarCitasOcupadas($conexion, $dia, $usuario) {
    $arreglo_variables = [
            'dia' => $dia,
            'usuario' => $usuario
    ];
    $consulta = "SELECT HORA,DNI_PACIENTE,FECHA FROM CITAS"
        . " WHERE (FECHA = TO_DATE(:dia,'DD/MM/YYYY')"
        . " AND USUARIO_MEDICO=:usuario"
        . " AND DNI_PACIENTE IS NOT NULL)"
        . " ORDER BY HORA";
    return $conexion->query($consulta,$arreglo_variables);
}

And so it should work fine and you would not see the error anymore.

* To satisfy your curiosity, there is very good information on this question about how to use better PDO and avoid the Sql injection, and also in case you wonder why you do not have to put the colon in" day "and" user " this question sure helps you .

    
answered by 21.08.2017 / 20:19
source