• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using $this->db->like without %

How can I use $this->db->like without % to be added on either of side that means my query should be something like this.

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.

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

why not use "where name = 'ci'" ?

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

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.

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.

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 =.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.