CodeIgniter Forums

Full Version: How to search between encoded data in mysql database?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

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:

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:

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;

    $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();        

El Forum

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.

El Forum

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?