How to use the %
operator, for bindValue()
, on query
below:
$sql = 'SELECT * FROM nfe WHERE (cliente LIKE :cliente OR :cliente_ IS NULL)';
How to use the %
operator, for bindValue()
, on query
below:
$sql = 'SELECT * FROM nfe WHERE (cliente LIKE :cliente OR :cliente_ IS NULL)';
Your SQL
would be:
$sql = 'SELECT * FROM nfe WHERE (cliente LIKE :cliente OR cliente IS NULL)';
I could realize there is an error.
Examples :
$stmt->bindValue(':cliente', $variavel."%", PDO::PARAM_STR);
or
$stmt->bindValue(':cliente', "$variavel%", PDO::PARAM_STR);
$stmt->bindValue(':cliente', "%".$variavel, PDO::PARAM_STR);
or
$stmt->bindValue(':cliente', "%$variavel", PDO::PARAM_STR);
$stmt->bindValue(':cliente', "%".$variavel."%", PDO::PARAM_STR);
or
$stmt->bindValue(':cliente', "%$variavel%", PDO::PARAM_STR);
References: