CodeIgniter Forums
How to search between encoded data in mysql database? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: How to search between encoded data in mysql database? (/thread-53004.html)



How to search between encoded data in mysql database? - El Forum - 07-06-2012

[eluser]afshin[/eluser]
I have encoded some data using codeigniter's encryption method and stored them in mysql database. There is no problem retrieving them, but when I want to search between them, it appears to be nonsense. How can I search between encoded data in mysql and codeigniter?

This is my encoding function:

Code:
function _encode($options = array()){

    $key = 'Q7tBBb1iECkl5Kk1U3mVPur1J863KGz4';

    $encoded = $this->encrypt->encode($options['code'], $key);

    return $encoded;
}


This is what I use as a search method in my Model:


Code:
function search()
{
    //Pagination config
    $search_by = $this->session->userdata('search_by');
    $search_term = $this->_encode($this->session->userdata('search_term'));

    $config['base_url'] = base_url() . 'acp/cds/search_result/page/';
    $config['total_rows'] = $this->db->like($search_by, $search_term)->get('cards')->num_rows();
    $config['per_page'] = 15;
    $config['num_links'] = 4;
    $config['uri_segment'] = 5;
    $this->pagination->initialize($config);

    $page_num = $this->uri->segment(5, 1);
    $offset = ($page_num - 1) * $config['per_page'];
    $this->db->order_by('card_Id', 'ASC');        
    $this->db->like($search_by, $search_term);
    $query = $this->db->get('cards', $config['per_page'], $offset);

    return $query->result();        
}



How to search between encoded data in mysql database? - El Forum - 07-06-2012

[eluser]PhilTem[/eluser]
There's no way to search for an encoded string in any other strings.

The only way you can deal with it: Get your data from the db, decode all encoded strings and then you can search it. Encoding data is not unique and therefore you wont get the same encoded string when you encode a string twice.


How to search between encoded data in mysql database? - El Forum - 07-06-2012

[eluser]afshin[/eluser]
But, if there are, for example, 1000 records in the database, it's going to be a process problem. What else I can do for it?