Under this tutorial, we are going to focus on how to use SQL LIKE Clause in a PDO Prepared Statement. LIKE clause in SQL is commonly used to search keywords from a database.

How to use SQL LIKE Clause in a PDO Prepared Statement

This code shows how to use LIKE clause in A PDO Prepared Statement

ALSO READ: How to add icon or Logo image in the title bar of browser.

[php]
require "config.inc.php"; // this represents your database connection file
$keyWord = "your keyword here"; // this can be a value from form or anything that user has typed on text field
try{
$query = $con->prepare("SELECT * FROM products WHERE name LIKE ? ");
$query->bindValue(1, "%$keyWord%");
$query->execute();

if($query->rowCount()){
echo "<center>Search results found</center>";
} else {
echo "<center>No search results found matching your keyword!</center>";
}
} catch(Exception $e){
die($e->getMessage());
}
[/php]



ALSO READ: UPDATED 2018, how bloggers are making money online

Reference

Read More on PDO PREPARED STATEMENTS

Similar Posts