# CodeIgniter 查询 - 保护标识符

**URL:** <https://www.isharkfly.com/t/codeigniter/3583>\
**Category:** PHP\
**Created:** [January 5, 2014, 6:33am UTC](https://www.isharkfly.com/t/codeigniter/3583 "2014-01-05T06:33:50Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![honeymoose](https://www.isharkfly.com/user_avatar/www.isharkfly.com/honeymoose/32/20796_2.png) [@honeymoose](https://www.isharkfly.com/u/honeymoose)\
**Post date:** [January 5, 2014, 6:33am UTC](https://www.isharkfly.com/t/codeigniter/3583/1 "2014-01-05T06:33:50Z")

</div>

在许多数据库中，保护表(table)和字段(field)的名称是明智的，例如在MySQL中使用反引号。

Active Record的查询都已被自动保护，然而，如果您需要手动保护一个标识符，您也可以这样：`$this->db->protect_identifiers('table_name');`这个函数也会给你的表名添加一个前缀，它假定在你的数据库配置文件中已指定了一个前缀。可通过将第二个参数设置为TRUE (boolen) 启用前缀:`$this->db->protect_identifiers('table_name', TRUE);`
