Welcome Guest, Not a member yet? Register   Sign In
Setting dbprefix for one Model

[eluser]Ben Bowler[/eluser]
I have two Codeigniter applications running from one database. Each has a different dbprefix but share a users table.

I've tried resetting the prefix with this:

However when called in a Model it is applied to all future queries. Do I have to re declare the prefix for each model or is there a way to do it by editing the core db library?

Any ideas would be much appreciated. I'll update here as I go.

[eluser]Ben Bowler[/eluser]
I used this:

$this->db->dbprefix = '';

You could create a second connection to your database that would be limited to your Users model scope, and set its prefix to nothing.

[eluser]Ben Bowler[/eluser]
Yes in the end I created another connection with a different prefix and it worked a treat!
$db['default']['hostname'] = '';
$db['default']['username'] = '';
$db['default']['password'] = '';
$db['default']['database'] = '';
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = 'prefix';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;

// Create shared prefix
$db['shared'] = $db['default'];
$db['shared']['dbprefix'] = 'shared_';

Then loaded this connection in Ion_auth:
class Ion_auth_model extends CI_Model

//  ...

public function __construct()
  $this->db = $this->load->database('shared', TRUE);

Theme © iAndrew 2016 - Forum software by © MyBB