CodeIgniter Forums
How to use AES_ENCRYPT on mysql inserts w/ CI? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: How to use AES_ENCRYPT on mysql inserts w/ CI? (/showthread.php?tid=12900)



How to use AES_ENCRYPT on mysql inserts w/ CI? - El Forum - 11-04-2008

[eluser]jamie young[/eluser]
I am new to CI, and was happy to see w/ just a few changes to my existing code I had it working in CI. I want to switch my DB inserts from standard queries over to CI's active record inserts but I have not found a way to deal with AES_ENCRYPT calls.

I had a query like this:

Code:
$query = "INSERT INTO user
          SET email = '{$data['email']}',
              password = AES_ENCRYPT('{$data['password']}', 'xxx'),
              user_type = '{$data['type']}',
              user_fname = '{$data['first_name']}',
              user_lname = '{$data['last_name']}'
";

Which I have converted to this:

Code:
$this->db->set('email', $data['email']);
$this->db->set('user_type', $data['type']);
$this->db->set('user_fname', $data['first_name']);
$this->db->set('user_lname', $data['last_name']);
$this->db->insert('user');

I am not sure how to get the password line in there though.


How to use AES_ENCRYPT on mysql inserts w/ CI? - El Forum - 11-04-2008

[eluser]GSV Sleeper Service[/eluser]
you don't have to use Active Record, in cases like this I'd just use the raw SQL you have in your first example. eg
Code:
$this->db->simple_query($query);



How to use AES_ENCRYPT on mysql inserts w/ CI? - El Forum - 11-04-2008

[eluser]Pascal Kriete[/eluser]
Alternatively, if you want to continue using AR, you can turn off escaping for that particular clause.
Code:
$this->db->set('password', "AES_ENCRYPT('{$data['password']}', 'xxx')", FALSE);