# CodeIgniter 查询 - 手动配置数据库前缀

**URL:** <https://www.isharkfly.com/t/codeigniter/5089>\
**Category:** PHP\
**Created:** [January 5, 2014, 6:31am UTC](https://www.isharkfly.com/t/codeigniter/5089 "2014-01-05T06:31:30Z")\
**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:31am UTC](https://www.isharkfly.com/t/codeigniter/5089/1 "2014-01-05T06:31:30Z")

</div>

如果你配置了数据库的前缀，如果你希望在你 SQL 使用的时候在你的表名称前面加上这些前缀，你可以使用下面的方法：`$this->db->dbprefix('tablename');
// outputs prefix_tablename`如果你希望能够能够在不重新建立数据库连接的情况下修改数据库的前缀，你可以使用下面的方法：[code]$this-\>db-\>set\_dbprefix(‘newprefix’);

$this-\>db-\>dbprefix(‘tablename’);  
// outputs newprefix\_tablename[/code]
