If I set PDO emulate to false, as I have read multiple times should be done for SQL injection security, using wildcards in a LIKE
query results in no output.
This is the setting:
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
this is a query that is failing:
$query = $db->prepare("SELECT * FROM video WHERE name like :search and removed='0' and verified='1' or subgenre like :search and removed='0' and verified='1' LIMIT :lb, :lt");
$query->bindValue(':search', '%'.$search.'%', PDO::PARAM_STR);
$query->bindValue(':lb', $limitbottom, PDO::PARAM_INT);
$query->bindValue(':lt', $limittop, PDO::PARAM_INT);
$query->execute();
$array = $query->fetchAll(PDO::FETCH_ASSOC);
if I remove the emulate setting, the query runs as expected and returns an array. If I understand everything correctly, setting emulate to false should be in the script to prevent SQL injection. How do I correct this? Is it possible to have like
queries with wildcards and emulation off?
PHP is 5.4.10 & MySQL is 5.1.66