what does fourth parameter ($escape) actually do for $builder->like? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28) +--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30) +--- Thread: what does fourth parameter ($escape) actually do for $builder->like? (/showthread.php?tid=78680) |
what does fourth parameter ($escape) actually do for $builder->like? - sneakyimp - 02-24-2021 I was expecting that the fourth parameter for the Builder::like function would cause special characters in the $match parameter to be escaped. I was quite surprised to see that supplying FALSE for this parameter results in no quotation marks for the $match parameter. Is this a bug? An example. I would expect the % in 'H%' to be escaped: PHP Code: function test2() { Code: SELECT * FROM `db_my_table` WHERE col1 LIKE 20% Code: SELECT * FROM `db_my_table` WHERE col1 LIKE '20%' PHP Code: $builder->like('col1', '20%', 'none', true); Code: SELECT * FROM `db_my_table` WHERE `col1` LIKE '20%' ESCAPE '!' Code: SELECT * FROM `db_my_table` WHERE col1 LIKE '20!%' ESCAPE '!' NOTE that in every case the table is surrounded by backticks, and the $escape parameter turns on/off the backticks around the column name and the quotes around the pattern to be matched. Can someone explain to me what the $escape parameter is really doing? The documentation is not very clear at all: Quote:$escape (bool) – Whether to escape values and identifiers RE: what does fourth parameter ($escape) actually do for $builder->like? - kenjis - 02-27-2021 In CI3, PHP Code: $this->db->like('col1', '20%', 'none', false); Code: SELECT * At least, the following SQL is invalid, and it must be a bug in CI4. Code: SELECT * FROM `db_my_table` WHERE col1 LIKE 20% |