Suppose i want to run query like this:
$q = "SELECT * FROM items WHERE name LIKE $1";
$r = pg_query_params($dbconn, $q, array("%" . $ss . "%"));
The problem may arise if user has supplied string with % or _ for $ss. How can i tell engine to not consider % and _ in $ss as special symbols?
For now my approach is
$q = "SELECT * FROM items WHERE name LIKE $1 ESCAPE '\'";
$r = pg_query_params($dbconn,
$q,
array("%" . str_replace("%", "\%", str_replace("_", "\_", $ss)) . "%"));
But what if escape character (\) is the last one in the string, then appended % will be escaped as well.