开发者

Select query in CodeIgniter

How the first query is different than second in CodeIgniter? and which one should be used in CodeIgniter?

1.

开发者_Python百科$query = $this->db->query('SELECT * FROM my_table WHERE email = $email LIMIT 1');

2:

$query = $this
            ->db
            ->where('email', $email)
            ->limit(1)
            ->get('my_table');

Thanks.


There's really no difference.

Enable the profiler and you will be able to see the actual queries run.

Active record is easier to use when building a query dynamically, and escapes the parameters automatically. Using $this->db->query() you must escape it yourself unless you want to use query bindings (see bottom of page).

Some queries are just to complicated to use Active Record efficiently, but not this one. Use whichever method you want, but my vote is for Active Record.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜