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?
This commit is contained in:
Tim Almdal
2009-02-27 03:25:29 +00:00
parent 0b055835fd
commit ab973bd871
2 changed files with 49 additions and 0 deletions
+16
View File
@@ -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);
}
}