diff options
author | Tim Almdal <tnalmdal@shaw.ca> | 2009-02-27 03:25:29 +0000 |
---|---|---|
committer | Tim Almdal <tnalmdal@shaw.ca> | 2009-02-27 03:25:29 +0000 |
commit | ab973bd87168ab11ff5242824738edb89f0bc3e2 (patch) | |
tree | afdc2a9650a9f19a43fa9ccf89c159032e705fab /core/libraries | |
parent | 0b055835fdecd9e560784ee23afa480328d8e742 (diff) |
Replace the string [table_name] with {$prefix}table_name. Slowly
working through setting up the database access to support table
prefixes. (Ticket#68)
Before going ahead, just wanted to check this approach... whatcha think?
Diffstat (limited to 'core/libraries')
-rw-r--r-- | core/libraries/MY_Database.php | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/core/libraries/MY_Database.php b/core/libraries/MY_Database.php index f5e412a6..7d6c3ece 100644 --- a/core/libraries/MY_Database.php +++ b/core/libraries/MY_Database.php @@ -42,4 +42,20 @@ class Database extends Database_Core { throw new Kohana_Database_Exception('database.missing_open_paren'); } + + /** + * Parse the query string and convert any strings of the form `\([a-zA-Z0-9_]*?)\] + * table prefix . $1 + */ + public function query($sql = '') { + if (!empty($sql)) { + $sql = $this->add_table_prefixes($sql); + } + return parent::query($sql); + } + + public function add_table_prefixes($sql) { + $prefix = $this->config["table_prefix"]; + return preg_replace("#\[([a-zA-Z0-9_]+)\]#", "{$prefix}$1", $sql); + } }
\ No newline at end of file |