mySqli Bind Parameter LIKE with Wildcard(mySqli 绑定参数 LIKE 与通配符)
问题描述
我在将带有通配符的 LIKE
绑定到 MySQLi 中准备好的语句时遇到问题.我尝试了以下两种方法,如下所示 &concat.(更新为@fancyPants 输入)
I'm having issues binding the LIKE
with Wildcard into my prepared statement in MySQLi. I tried both the following methods below as shown & concat.(updated with @fancyPants input)
有没有办法在绑定发生后查看自己的 SQL 语句?
Is there a way so that I can view my own SQL statement after the binding happens?
如何正确绑定以获得我想要的结果?
How do I bind it properly to get the result I want ?
它可以在没有 LIKE 语句的情况下工作.
It works without the LIKE statement.
我只能从使用某个搜索词中提取数据.我的代码有问题吗?
I could only pull out data from using a certain search term. Is there anything wrong with my code?
$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, $bookTitle, $bookPrice);
while ($stmt->fetch()) {
echo $bookTitle;
}
这篇关于mySqli 绑定参数 LIKE 与通配符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:mySqli 绑定参数 LIKE 与通配符


基础教程推荐
- mysqli_insert_id 是否有可能在高流量应用程序中返回 2021-01-01
- 在 Woocommerce 中根据运输方式和付款方式添加费用 2021-01-01
- WooCommerce 中选定产品类别的自定义产品价格后缀 2021-01-01
- Libpuzzle 索引数百万张图片? 2022-01-01
- XAMPP 服务器不加载 CSS 文件 2022-01-01
- 超薄框架REST服务两次获得输出 2022-01-01
- 在多维数组中查找最大值 2021-01-01
- 通过 PHP SoapClient 请求发送原始 XML 2021-01-01
- 在 PHP 中强制下载文件 - 在 Joomla 框架内 2022-01-01
- 如何在 PHP 中的请求之间持久化对象 2022-01-01