Welcome Guest, Not a member yet? Register   Sign In
How to use a database prefix within controllers?
#1

[eluser]fancms[/eluser]
For most of my database queries I am using the Active Record Class. Occasionally I have the need to use a straightforward $this->db->query syntax, and it is here that I have issues, as I use a database prefix (ie prefix_ produces prefix_tablename).

Is there a way to access the dbprefix from the /config/Database.php class? I've tried several different methods, including $this->database->default('dbprefix')and $db['default']['dbprefix'], and needless to say, they don't work.

I'm not sure if I'm going about this the wrong way? :red:
#2

[eluser]Phil Sturgeon[/eluser]
Quite a simple on this.
Code:
// Use
$this->db->dbprefix;

// Example
$this->db->query('SELECT * FROM '.$this->db->dbprefix.$tablename);
#3

[eluser]fancms[/eluser]
Oh geez; that was embarassingly simple :red: Thank you, the pyromaniac!




Theme © iAndrew 2016 - Forum software by © MyBB