Working with the LIKE Operator in PDO in PHP
To use the
LIKE operator in a prepared query,
you need to specify
the value for its variable
using a special
syntax:
<?php
$var = '%value%';
?>
Let's find a user by name,
using the LIKE operator:
<?php
$name = '%user1%';
$res = $pdo->prepare('SELECT * FROM users WHERE name LIKE ?');
$res->execute([$name]);
$row = $res->fetchAll();
var_dump($row);
?>
Display all users
from the users table,
whose salary is equal to
500.
Display users
whose salary is equal to or more than
900, and whose age
is less than 35 years.