summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--system/database/DB_active_rec.php27
-rw-r--r--user_guide/changelog.html1
-rw-r--r--user_guide/database/queries.html4
3 files changed, 29 insertions, 3 deletions
diff --git a/system/database/DB_active_rec.php b/system/database/DB_active_rec.php
index 08213af5c..ba68e1e8f 100644
--- a/system/database/DB_active_rec.php
+++ b/system/database/DB_active_rec.php
@@ -7,8 +7,8 @@
* @package CodeIgniter
* @author ExpressionEngine Dev Team
* @copyright Copyright (c) 2006, EllisLab, Inc.
- * @license http://codeigniter.com/user_guide/license.html
- * @link http://codeigniter.com
+ * @license http://www.codeigniter.com/user_guide/license.html
+ * @link http://www.codeigniter.com
* @since Version 1.0
* @filesource
*/
@@ -24,7 +24,7 @@
* @subpackage Drivers
* @category Database
* @author ExpressionEngine Dev Team
- * @link http://codeigniter.com/user_guide/database/
+ * @link http://www.codeigniter.com/user_guide/database/
*/
class CI_DB_active_record extends CI_DB_driver {
@@ -45,6 +45,27 @@ class CI_DB_active_record extends CI_DB_driver {
var $ar_aliased_tables = array();
/**
+ * DB Prefix
+ *
+ * Prepends a database prefix if one exists in configuration
+ *
+ * @access public
+ * @param string the table
+ * @return string
+ */
+ function dbprefix($table = '')
+ {
+ if ($table == '')
+ {
+ $this->display_error('db_table_name_required');
+ }
+
+ return $this->dbprefix.$table;
+ }
+
+ // --------------------------------------------------------------------
+
+ /**
* Select
*
* Generates the SELECT portion of the query
diff --git a/user_guide/changelog.html b/user_guide/changelog.html
index 66aa63539..8b086fb44 100644
--- a/user_guide/changelog.html
+++ b/user_guide/changelog.html
@@ -88,6 +88,7 @@ Change Log
<li>Other Database Related
<ul>
<li>Added $this->DB->save_queries variable to DB driver, enabling queries to get saved or not. Previously they were always saved.</li>
+ <li>Added $this->db->dbprefix() to manually add database prefixes.</li>
<li>Added 'random' as an <kbd>order_by()</kbd> option , and removed &quot;rand()&quot; as a listed option as it was MySQL only.</li>
<li>Added a check for NULL fields in the MySQL database backup utility.</li>
<li>Added &quot;constrain_by_prefix&quot; parameter to db-&gt;list_table() function. If set to TRUE it will limit the result to only table names with the current prefix.</li>
diff --git a/user_guide/database/queries.html b/user_guide/database/queries.html
index 7e9d05d7b..19b33d5e1 100644
--- a/user_guide/database/queries.html
+++ b/user_guide/database/queries.html
@@ -80,6 +80,10 @@ It DOES NOT return a database result set, nor does it set the query timer, or co
It simply lets you submit a query. Most users will rarely use this function.</p>
+<h1>Adding Database prefixes manually</h1>
+<p>If you have configured a database prefix and would like to add it in manually for, you can use the following.</p>
+<p><code>$this-&gt;db-&gt;dbprefix('tablename');<br />
+// outputs prefix_tablename</code></p>
<h1>Protecting identifiers</h1>
<p>In many databases it is advisable to protect table and field names - for example with backticks in MySQL. Active Record queries are automatically protected, however if you need to manually protect an identifier you can use:</p>
<p><code>$this-&gt;db-&gt;protect_identifier('table_name');</code></p>