Welcome Guest, Not a member yet? Register   Sign In
Can I use AES_ENCRYPT and Active Record insert?
#1

[eluser]Adam_R[/eluser]
How can I use AES_ENCRYPT and CI2 db->insert?

My code looks like:

Code:
public function storeData($name){

  $data = array('stamp' => mktime(0,0,0,date('n'),date('j'),date('Y')));

  foreach($_POST as $field => $value) {

   $data[$field] = $value;
  }  
  
  return $this->db->insert($name, $data);
}

is this correct?

Code:
foreach($_POST as $field => $value) {

   $data[$field] = AES_ENCRYPT($value,$this->config->item('encryption_key'));
  }

or rather that:

Code:
foreach($_POST as $field => $value) {

     $this->db->set($field, "AES_ENCRYPT('{$value}', $this->config->item('encryption_key'))", FALSE);  
  }  
  
  return $this->db->insert($name);

Thanks
#2

[eluser]Adam_R[/eluser]
I think I found resolution:

Code:
foreach($_POST as $field => $value) {

   $this->db->set($field, "AES_ENCRYPT(".$this->db->escape($value).", '".$this->config->item('encryption_key')."')", FALSE);  
  }  
  
  return $this->db->insert($name);

Any other solutions?




Theme © iAndrew 2016 - Forum software by © MyBB