带有LIKE的php-sql-odbc_execute()不起作用


php sql odbc_execute() with LIKE not working

所以我有一段代码没有返回任何内容(echo什么都不返回,应该返回两行):

<?php
include "connection.php";
$cliente = $_POST["cliente"];
$select = "SELECT CLIENTE, NOMCLI FROM CLIX1 WHERE NOMCLI LIKE ? ORDER BY NOMCLI";
$stmt = odbc_prepare($con, $select);
//preparing the array for parameter
$prep_array = array();
$prep_array[] = "'%$cliente%'";
$rs = odbc_execute($stmt, $prep_array);
$nombres = array();
$clienteIDS = array();
//if prepare statement is 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);

?>

我知道问题不在于odbc_execute()上的参数传递,因为即使我这样做,它也不会返回任何内容(使用%mich%,它应该显示两行):

$rs = odbc_execute($stmt, array("%mich%"));

你看到这个代码有什么错误吗?

请提前通知我并表示感谢。

更新------

我对下面的答案中建议的代码进行了更改,现在我得到了一个新的错误:

Warning: odbc_execute(): Can't open file %mich%

其中mich是要在数据库中搜索的文本。

我发现了以下可能相关的内容:PHP 中ODBC准备的语句

$prep_array = array();
$prep_array[] = "'%$cliente%'";
$rs = odbc_execute($stmt, $prep_array);

我认为双引号可能会引起问题。