Welcome Guest, Not a member yet? Register   Sign In
How to use AES_ENCRYPT on mysql inserts w/ CI?
#1

[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.
#2

[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);
#3

[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);




Theme © iAndrew 2016 - Forum software by © MyBB