what does fourth parameter ($escape) actually do for $builder->like? |
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
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% |
Welcome Guest, Not a member yet? Register Sign In |