Problem with % in parameter value
Probably not a problem with the code (which I have been using for years and find to be excellent! Thank you!), but with my use of it.
My code
$sqlText = 'SELECT count(*) AS count FROM recruiters WHERE recruiter_email LIKE "%:agencyEmailDomain"';
$sqlParameters = array('agencyEmailDomain' => $agencyEmailDomain);
where $agencyEmailDomain == "gmail.com"
and $expandedSqlCommand = PdoDebugger::show($sqlText, $parameters);
expanded to
SELECT count(*) AS count FROM recruiters WHERE recruiter_email LIKE "%'Gmail.com'"
Notice those single quotes around the domain name?
Is there something that I can do, like escaping the % sign?
Thanks in advance for your help.
Never mix wildcards in your prepared statement and instead use them as part of your value you are binding to the placeholder parameter like so:
See: https://stackoverflow.com/questions/16255657/pdo-prepared-statements-with-wildcards
$name = "%$name%";
$query = $dbh->prepare("SELECT * FROM gc_users WHERE name like :name");
$query->bindParam(':name', $name);
$query->execute();