How to use LIKE in bindValue?

2

How to use the % operator, for bindValue() , on query below:

$sql = 'SELECT * FROM nfe WHERE (cliente LIKE :cliente OR :cliente_ IS NULL)';
    
asked by anonymous 26.02.2017 / 01:00

1 answer

2

Your SQL would be:

$sql = 'SELECT * FROM nfe WHERE (cliente LIKE :cliente OR cliente IS NULL)';

I could realize there is an error.

Examples :

Let start with the informed term:

$stmt->bindValue(':cliente', $variavel."%", PDO::PARAM_STR);

or

$stmt->bindValue(':cliente', "$variavel%", PDO::PARAM_STR);

End with informed endorsement:

$stmt->bindValue(':cliente', "%".$variavel, PDO::PARAM_STR);

or

$stmt->bindValue(':cliente', "%$variavel", PDO::PARAM_STR);

In any part of the informed term:

$stmt->bindValue(':cliente', "%".$variavel."%", PDO::PARAM_STR);

or

$stmt->bindValue(':cliente', "%$variavel%", PDO::PARAM_STR);

References:

26.02.2017 / 03:06