Active Record : LIKE without wildcard (%) |
[eluser]HattoriHanzo[/eluser]
You have mentioned in change log and new user guide that new capability of using "LIKE" without wildcard (%) has been added to the new version (2.1.0) : in this link : http://ellislab.com/codeigniter/user-gui...gelog.html "Added additional option 'none' for the optional third argument for $this->db->like() in the Database driver." But it seems you forgot to include it in uploaded files!!!! I added this code segment to "DB_active_rec.php" file @ line 672 : Code: elseif ($side == 'none')
[eluser]pickupman[/eluser]
This code was added back on 8/21 see the [url="https://github.com/EllisLab/CodeIgniter/commit/ea4ad9b4e7ab7824da4274e30075fd36a6bf9952"]commit[/url]. It was add the week after 2.1.0 was tagged and released.
[eluser]HattoriHanzo[/eluser]
[quote author="pickupman" date="1327866015"]This code was added back on 8/21 see the [url="https://github.com/EllisLab/CodeIgniter/commit/ea4ad9b4e7ab7824da4274e30075fd36a6bf9952"]commit[/url]. It was add the week after 2.1.0 was tagged and released.[/quote] I've just downloaded it again and there is no change!!!! here is download link, check it yourself. ![]() Official Download Link From Home Page : codeigniter[.]com/download_files/reactor/CodeIgniter_2.1.0.zip
[eluser]pickupman[/eluser]
If you notice, I mentioned is was added <b>after</b> 2.1.0 was tagged and released. The next version has not been released, so when you download from the homepage you are still getting 2.1.0 and not the latest. Try clicking on the commit link in my message above and you will see the code is in fact there.
[eluser]HattoriHanzo[/eluser]
[quote author="pickupman" date="1327931427"]If you notice, I mentioned is was added <b>after</b> 2.1.0 was tagged and released. The next version has not been released, so when you download from the homepage you are still getting 2.1.0 and not the latest. Try clicking on the commit link in my message above and you will see the code is in fact there.[/quote] Oh, sorry. My poor English :-"
[eluser]Aken[/eluser]
Code: $this->db->like('column', 'value', 'none'); Code: $this->db->where('column', 'value');
[eluser]HattoriHanzo[/eluser]
[quote author="Aken" date="1327970940"] Code: $this->db->like('column', 'value', 'none'); Code: $this->db->where('column', 'value'); If you want to compare an Integer value like 'id' in your query and your input value is something like this ("2sad2s") , using "WHERE" in Active Records, create a query like this : SELECT * FROM my_table WHERE id = "2sad2s" ; As a result, MYSQL convert the string to an integer ("2" in this case) and run the query and return record corresponding to that row. But this is a semantic error. The result is equivalent to this query : SELECT * FROM my_table WHERE id = "2" ; Instead of "WHERE", When you use "LIKE", there is no change in your input value. SELECT * FROM my_table WHERE id LIKE "2sad2s" ; Of course another solution is getting intval() of input value.
[eluser]Aken[/eluser]
Hm, I've never ran into that before. Interesting. In that case, I suggest that you validate the input before using it as a comparison in your database. If you know you're going to compare an integer field in your database, your PHP should make sure the value is an integer before it gets anywhere near the DB. I wouldn't recommend intval() either, since it'll do the same thing that MySQL does in that it'll turn a string like "2sad2s" into int(2). You want to validate directly against user input, not what PHP might think it should be.
[eluser]HattoriHanzo[/eluser]
[quote author="Aken" date="1327993726"]Hm, I've never ran into that before. Interesting. In that case, I suggest that you validate the input before using it as a comparison in your database. If you know you're going to compare an integer field in your database, your PHP should make sure the value is an integer before it gets anywhere near the DB. I wouldn't recommend intval() either, since it'll do the same thing that MySQL does in that it'll turn a string like "2sad2s" into int(2). You want to validate directly against user input, not what PHP might think it should be.[/quote] I validate my Integer inputs like this : Code: if(strcmp(intval($input),$input)!=0)
[eluser]danmontgomery[/eluser]
[quote author="Aken" date="1327970940"] Code: $this->db->like('column', 'value', 'none'); Code: $this->db->where('column', 'value'); LIKE is case insensitive, WHERE is not |
Welcome Guest, Not a member yet? Register Sign In |