Anil Anil - 4 years ago 144
SQL Question

Convert following MySQL query to Codeigniter equivalent

I'm very new to CodeIgniter and I have some problem converting MySQL queries to CodeIgniter. I want to update a record in one table with condition on another relational table.

Following is my MySQL query

UPDATE `user` SET `securitytoken` = '71b9b5bc1094ee6eaeae8253e787d654'
WHERE `profileid` IN (SELECT pid FROM `profile` WHERE `email` = '')

This works fine in phpMyAdmin, but I wanted the same to be converted to codeigniter update query. Can anyone help me to convert.

I'm using CI v3.0.3 in Local WAMP Server.

Thanks in Advance

Answer Source

What I would do is code your query as is using

$query = $this->db->query('YOUR QUERY HERE');

and use the escape capabilities to take care of your one or two input values.

Pay attention to query bindings, may be useful in your case.


I would not try to use Active Records, your SQL is a bit too complex for that.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download