sql server - php sql odbc_execute() with LIKE not working -
so have piece of code not returning (the echo returns nothing , should returning 2 rows):
<?php include "connection.php"; $cliente = $_post["cliente"]; $select = "select cliente, nomcli clix1 nomcli ? order nomcli"; $stmt = odbc_prepare($con, $select); //preparing array parameter $prep_array = array(); $prep_array[] = "'%$cliente%'"; $rs = odbc_execute($stmt, $prep_array); $nombres = array(); $clienteids = array(); //if prepare statement successful if($rs) { $i = 0; while($row=odbc_fetch_array($stmt)) { $cliente_id = trim($row["cliente"]); $nombre = utf8_encode(trim($row["nomcli"])); $nombres[$i] = $nombre; $clienteids[$i] = $cliente_id; $i++; } echo json_encode($nombres) . "|" . json_encode($clienteids); } else { echo "error"; } odbc_close($con); ?>
i know problem not parameter pass on odbc_execute() because if this, doesn't return anything(with %mich% should display 2 rows):
$rs = odbc_execute($stmt, array("%mich%"));
do see wrong in code?
please let me know , in advance.
update ------
i made changes on code suggested on answer below , getting new error now:
warning: odbc_execute(): can't open file %mich%
where mich text entered search on database.
i found following may relate: odbc prepared statements in php
$prep_array = array(); $prep_array[] = "'%$cliente%'"; $rs = odbc_execute($stmt, $prep_array);
i think double quotes might causing issue.