Php 在mysqli中多次使用同一活页夹

Php 在mysqli中多次使用同一活页夹,php,mysql,mysqli,Php,Mysql,Mysqli,我正在编写一个小php程序,我是PDO新手。 我的程序中有一个实时搜索组件。 用户的查询应使用两个表列进行搜索。 我知道如何用传统的mysql编写查询 但我不知道如何在mysqli中做到这一点。 当我运行以下代码时,它将显示以下错误 Warning: mysqli_stmt_bind_param(): Number of variables doesn't match number of parameters in prepared statement in 下面是我的代码 if(isset

我正在编写一个小php程序,我是PDO新手。 我的程序中有一个实时搜索组件。 用户的查询应使用两个表列进行搜索。 我知道如何用传统的mysql编写查询

但我不知道如何在mysqli中做到这一点。 当我运行以下代码时,它将显示以下错误

Warning: mysqli_stmt_bind_param(): Number of variables doesn't match number of parameters in prepared statement in 
下面是我的代码

if(isset($_REQUEST['term'])){
     // Prepare a select statement
     $sql = 'SELECT * FROM items WHERE (i_name LIKE ?) OR (i_code LIKE ?)';

     if($stmt = mysqli_prepare($ds, $sql)){
         // Bind variables to the prepared statement as parameters
         mysqli_stmt_bind_param($stmt, "s", $param_term);

         // Set parameters
         $param_term = $_REQUEST['term'] . '%';

         // Attempt to execute the prepared statement
         if(mysqli_stmt_execute($stmt)){
             $result = mysqli_stmt_get_result($stmt);

             // Check number of rows in the result set
             if(mysqli_num_rows($result) > 0){
                 // Fetch result rows as an associative array
                echo '<table class="table table-striped"><tbody><tr>';
                 while($row = mysqli_fetch_array($result, MYSQLI_ASSOC)){

                    echo '<td width="70%">' . $row["i_name"] . '</td><td width="30%"><a href="edit-cat.php?cat='.$row['iid'].'"><i class="fa fa-pencil" aria-hidden="true"></i> Edit</a></td>';
                 }
                echo '</tr></tbody></table>';
             } else{
                 echo "<p>No matches found</p>";
             }
         } else{
             echo "ERROR: Could not able to execute $sql. " . mysqli_error($ds);
         }
     }

     // Close statement
     mysqli_stmt_close($stmt);
 }

 // close connection
 mysqli_close($ds);
 ?>
jQuery

<script>
function selectCountry(val) {
$("#search-box").val(val);
$("#suggesstion-box").hide();
}
$(document).ready(function(){
    $('.search-box input[type="text"]').on("keyup input", function(){
        var inputVal = $(this).val();
        var resultDropdown = $(this).siblings(".result");
        if(inputVal.length){
            $.get("search-item.php", {term: inputVal}).done(function(data){
                resultDropdown.html(data);
            });

        } else{
            resultDropdown.empty();
        }
    });
    $(document).on("click", ".result p", function(){
        $(this).parents(".search-box").find('input[type="text"]').val($(this).text());
        $(this).parent(".result").empty();
    });
});
</script>

由于查询中有两个占位符,因此需要在mysqli_stmt_bind_param中使用两个变量。可以同时使用同一变量绑定多个占位符

mysqli_stmt_bind_param($stmt, "ss", $param_term, $param_term);

那么可能没有匹配的搜索词。var_转储$term的是什么;显示您希望数据库中的哪些行匹配?有几个匹配项。前面,如果我在查询中只使用一个条件,它会成功地打印db值。我需要匹配“I_name”和“I_code”列,如果它使用或不能返回较少的匹配项,则需要匹配“I_name”和“I_code”列。这是单列搜索“ifisset$\u REQUEST['term']]{//Prepare a select statement$sql='select*FROM items WHERE I_name LIKE?;//或I_code LIKE?”的查询,如果$stmt=mysqli_Prepare$ds,$sql{//Bind变量作为参数mysqli_stmt_Bind_param$stmt,s,$param_term;//设置参数$param_term=$\u REQUEST['term'].%';`不要在注释中粘贴代码,将其添加到问题中。
mysqli_stmt_bind_param($stmt, "ss", $param_term, $param_term);