0

I have the following code

    $stmt = odbc_prepare($conn, 'SELECT tpedidos.*, users.nome FROM tpedidos, users WHERE CODCLI IN (SELECT idCliente FROM ligacoes WHERE idGest =?) AND tpedidos.estado =? AND users.id=tpedidos.CODCLI');
    $success = odbc_execute($stmt, array($gestor, $estado));

My problem is that the $gestor is not being well read in the query and if i put a value instead of the '?' it works.

What can i do?

Thanks in advance!

EDIT 1:

Warning: odbc_execute(): SQL error: [Microsoft][ODBC SQL Server Driver]Syntax error or access violation, SQL state 37000 in SQLDescribeParameter in C:****\file.php on line 720

Cacheira
  • 19
  • 6

1 Answers1

0

To reply your last comment regarding an alternative query, you could try with PDO prepared statement:

$sth = $conn->prepare("SELECT tpedidos.*, users.nome 
                          FROM tpedidos, users 
                          WHERE CODCLI IN 
                            (SELECT idCliente FROM ligacoes WHERE idGest = :idGest) 
                          AND tpedidos.estado = :estado 
                          AND users.id = tpedidos.CODCLI");
$sth->bindParam(':idGest', $gestor, PDO::PARAM_INT);
$sth->bindParam(':estado', $estado, PDO::PARAM_STR);
$sth->execute();

P.S: I assumed $estado is a string. If it is an integer replace PDO::PARAM_STR with PDO::PARAM_INT.

hatef
  • 5,491
  • 30
  • 43
  • 46