How you can use the LIKE search with PDO

Hi guys! Today I want to explain you how you can use the LIKE search with PDO.

Let's suppose that the variable $search contains the search keywords.

I will add %% to the $search variable:

$search = "%".$search."%";

Next, I will write the search query:

$stmt = $this->db->prepare("SELECT * FROM table WHERE `name` LIKE :string");
$stmt->bindParam(':string',$search);
$stmt->execute();
$res = $stmt->fetchALL();

This code works like a charm!









Leave a Comment