0

I should execute this method,
but I don't know how pass %research value as LIKE parameter in bind:

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;
}
Dharman
  • 30,962
  • 25
  • 85
  • 135
  • Does [this](https://stackoverflow.com/questions/2722136/mysql-pdo-how-to-bind-like) help? – vee Dec 25 '21 at 21:15

1 Answers1

1

At least you can use in your query CONCAT function like next:

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

Note: if $research variable gets value '', then query will return all rows from the table.

Aksen P
  • 4,564
  • 3
  • 14
  • 27