PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, March 1, 2022

[FIXED] CodeIgniter MySQL LIKE query is not working

 March 01, 2022     codeigniter, mysql, php, search     No comments   

Issue

I am trying to get result from advertisement table by searching phone number from using mysql "LIKE" query. I tried many times but I did not get result.

public function searching($key){
     
    $this->db->select('*');
    $this->db->from('advertisement');
    $this->db->where('phone',$key);

    $query = $this->db->get();

    if($query->num_rows()>0) {
        echo "YES";
    }
    else{
        echo "NO";
    }
}

I got "YES" as a result when using "where" clause. But when I searching same phone number with "like" clause($this->db->like('phone',$key);) instead of "where", I got "NO", as a result.


Solution

Adding it as an answer for future seekers.

The field PHONE is probably setup as an INTEGER and you cannot use LIKE on an integer. There will be a mysql error thrown but if debug is off or something else is turned off it will never show.



Answered By - Forbs
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing