【问题标题】:MySQL LIKE operator in PHP [duplicate]PHP中的MySQL LIKE运算符[重复]
【发布时间】:2022-01-25 15:56:59
【问题描述】:

我应该执行这个方法,
但我不知道如何在绑定中将 %research 值作为 LIKE 参数传递:

public function researchElements($research) {
    $stmt = $this->db->prepare("SELECT * FROM product WHERE product_name LIKE "'%?%'"");
    $stmt->bind_param('s', $research);
    $stmt->execute();
    $result = $stmt->get_result();
    $result = $result->fetch_all(MYSQLI_ASSOC);

    return $result;
}

【问题讨论】:

  • this 有帮助吗?

标签: php sql mysqli


【解决方案1】:

至少你可以在你的查询中使用CONCAT 函数,比如下一个:

$stmt = $this->db->prepare("SELECT * FROM product WHERE product_name LIKE CONCAT('%',?,'%')"); 

注意:如果$research 变量获得值'',则查询将返回表中的所有行。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-06-05
    • 2014-02-14
    • 2013-02-08
    • 1970-01-01
    • 2019-10-19
    • 2013-01-24
    • 2011-12-06
    • 2010-10-10
    相关资源
    最近更新 更多