• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Setting dbprefix for one Model

#1
[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:
Code:
$this->db->set_dbprefix('newprefix');

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.

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

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

#3
[eluser]Aken[/eluser]
You could create a second connection to your database that would be limited to your Users model scope, and set its prefix to nothing.

#4
[eluser]Ben Bowler[/eluser]
Yes in the end I created another connection with a different prefix and it worked a treat!
Code:
$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:
Code:
class Ion_auth_model extends CI_Model
{

//  ...

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


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.