CodeIgniter Forums
Using $this->db->like without % - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: Using $this->db->like without % (/showthread.php?tid=16948)



Using $this->db->like without % - El Forum - 03-21-2009

[eluser]Computerzworld[/eluser]
Hello,
How can I use $this->db->like without % to be added on either of side that means my query should be something like this.

Code:
select * from tablename where name like 'ci';

But $this->db->like contains options as match,before,after,both. But what about not using wildcards? Please help me.Thanks in advance.


Using $this->db->like without % - El Forum - 03-21-2009

[eluser]TheFuzzy0ne[/eluser]
Have you tried running that query on your database to see how many results it returns? Try it, that might answer your question. Smile


Using $this->db->like without % - El Forum - 03-21-2009

[eluser]xwero[/eluser]
why not use "where name = 'ci'" ?


Using $this->db->like without % - El Forum - 03-21-2009

[eluser]TheFuzzy0ne[/eluser]
Exactly so. LIKE is used for wildcard comparisons. LIKE without a wildcard, is like running a car without fuel. It simply won't work.


Using $this->db->like without % - El Forum - 03-22-2009

[eluser]Computerzworld[/eluser]
hmm Smile the reason why i am gonna use it is that i read somewhere when using string comparisons use like with no wildcards around them it will be more effective than traditional '=' comparison.


Using $this->db->like without % - El Forum - 03-22-2009

[eluser]TheFuzzy0ne[/eluser]
It depends which way you look at it. If you see not making any matches as more efficient, then yes, I guess it is... Where did you read this?

LIKE was created for specifically for wildcard matches. I would have thought that = would actually be a lot quicker as it's making a straight match, and not having to use any kind of algorithm on the resulting string.


Using $this->db->like without % - El Forum - 03-23-2009

[eluser]xwero[/eluser]
In some cases like gets different results than =, for example 'a' = 'a ' gets another result than 'a' like 'a ' but normally you get this by trimming the posted value and using =.