CodeIgniter是否支持命名查询绑定? [英] Does CodeIgniter support named query binding?

查看:96
本文介绍了CodeIgniter是否支持命名查询绑定?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我检查了CI的手册,发现它支持这种查询绑定:

I checked the manual of CI and found it supports this kind of query binding:

$sql = "SELECT * FROM some_table WHERE id = ? AND status = ? AND author = ?";
$this->db->query($sql, array(3, 'live', 'Rick')); 

但我更喜欢PDO风格:

However I prefer the PDO style:

$sql = "SELECT * FROM some_table WHERE id = :id AND status = :status  AND author = :author";

以这种方式,绑定可以更灵活,顺序无关紧要。

In this way the binding could be more flexible and sequence would not matter.

CI是否支持那种绑定?

Does CI support that kind of binding?

推荐答案

默认情况下Codeigniter不支持named绑定。

By default Codeigniter doesn't support named bindings.

因为事实上它更容易使用命名绑定,所以我黑客了数据库类,以便它接受命名或未命名的绑定。

Because the fact that it is much more readable with named bindings, i "hacked" the database class so that it accept named or unnamed bindings.

如果有人对黑客感兴趣,请告诉我,我会将它上传到某处

If anyone is interesting in the "hack", let me know and i will upload it somewhere

这篇关于CodeIgniter是否支持命名查询绑定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆