How would i use code igniters active records to insert/update/select data from a database using mysql's built in aes encrypt/decrypt functions?
I know i could just use the normal sql query, but i'd like to use active records ideally.
Thanks
If you use the code provided previously:
$this->db->set('password',"AES_ENCRYPT('{$data['password']}','my_key')",FALSE);
you should still escape the password before passing it into db->set
use:
$pass = $this->db->escape($data['password']);
That way if the password contains special chars it won't kill the query
You can still use AES_Encrypt if you turn off escaping for that particular clause by passing FALSE as the last parameter:
$pass = $this->db->escape($data['password']);
$this->db->set('password', "AES_ENCRYPT('{$pass}','my_key')", FALSE);
Also point you to the CI built-in Encryption Class, and an article on considering 1-way encryption.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With