php – mySqli使用通配符绑定参数LIKE

前端之家收集整理的这篇文章主要介绍了php – mySqli使用通配符绑定参数LIKE前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我遇到了将LIKE与Wildcard绑定到我在 MySQLi中准备好的语句的问题.我尝试了以下两种方法,如图所示& concat.(用@fancyPants输入更新)

>有没有办法让我可以在绑定发生后查看自己的sql语句?
>如何正确绑定它以获得我想要的结果?

它没有LIKE语句.

我只能从使用某个搜索词中提取数据.我的代码有什么问题吗?

$str = $_POST["searchstr"];


    if(isset($_POST['submit']))
    {
        $price=$_POST['price'];


        if(!empty($_POST['chkbx']))
        {
            foreach($_POST['chkbx'] as $selected)
            {


                $sql= 'SELECT bookTitle,bookPrice FROM nbc_book WHERE catID LIKE "%'.$selected.'%" AND bookTitle LIKE "%'.$str.'%" AND bookPrice < ?';
                $stmt=MysqLi_prepare($con,$sql);
                MysqLi_stmt_bind_param($stmt,"i",$price);
                MysqLi_stmt_execute($stmt);
                MysqLi_stmt_bind_result($stmt,$bookTitle,$bookPrice); 
                while ($stmt->fetch()) {
                     echo $bookTitle.$bookPrice."<br>";
                }
            }
        }
    }
$searchStr =  'oracle';
$sql= 'SELECT bookTitle,bookPrice FROM nbc_book WHERE catID LIKE ? AND bookTitle LIKE "%'.$searchStr.'%" AND bookPrice < ?';
$stmt=MysqLi_prepare($con,$sql);
MysqLi_stmt_bind_param($stmt,"ssi",$selected,$price);
MysqLi_stmt_execute($stmt);
MysqLi_stmt_bind_result($stmt,$bookPrice); 
while ($stmt->fetch()) {
    echo $bookTitle;
}
原文链接:https://www.f2er.com/php/139094.html

猜你在找的PHP相关文章