How can wildcards like % be utilized in LIKE queries to enhance search capabilities in PHP applications?

In PHP applications, wildcards like % can be utilized in LIKE queries to enhance search capabilities by allowing for more flexible matching criteria. By using % as a wildcard character in conjunction with the LIKE operator, you can perform partial matching searches that match a specified pattern within a string. This can be particularly useful when searching for data in a database where the exact value may not be known.

// Example of using wildcards in a LIKE query to search for names starting with 'J'
$searchTerm = 'J%';
$sql = "SELECT * FROM users WHERE name LIKE :searchTerm";
$stmt = $pdo->prepare($sql);
$stmt->execute(['searchTerm' => $searchTerm]);
$results = $stmt->fetchAll();