2

Is it possible to use different database for authenticating user through Ion Auth? I would like to create a database dedicated only for user authentication. So, it should be separated from transactional database. How to do that?

Thank you.

user1134475
  • 415
  • 1
  • 8
  • 18
  • what database are you using ? – arty Feb 18 '14 at 09:17
  • possible duplicate of [Codeigniter - multiple database connections](http://stackoverflow.com/questions/8268853/codeigniter-multiple-database-connections) – arty Feb 23 '14 at 17:35

2 Answers2

2

In short...yes it is possible for you to use a different database for your authentication. You would need to create a second database configuration in your application/config/database.php file (similar to the below) in addition to your default config.

$db['default']['hostname'] = "localhost";
$db['default']['username'] = "root";
$db['default']['password'] = "";
$db['default']['database'] = "db_name";
$db['default']['dbdriver'] = "mysql";

$db['authentication']['hostname'] = "localhost";
$db['authentication']['username'] = "root";
$db['authentication']['password'] = "";
$db['authentication']['database'] = "auth_db_name";
$db['authentication']['dbdriver'] = "mysql";

For further reference see - http://ellislab.com/codeigniter/user-guide/database/configuration.html

You would then have to modify your ion_auth model to use this second db configuration, which you would set when loading the database.

$auth_db = $this->load->database('authentication', TRUE);

Then change all database queries in the model replacing $this->db with $auth_db.

So, $this->db->select('password, salt') would become $auth_db->select('password, salt').

For further reference see - http://ellislab.com/codeigniter/user-guide/database/connecting.html

Hope that helps!

MY_Mark
  • 1,059
  • 7
  • 8
2

The simplest way would be to expand on what MY_Mark said.

Create the new DB config

$db['authentication']['hostname'] = "localhost";
$db['authentication']['username'] = "root";
$db['authentication']['password'] = "";
$db['authentication']['database'] = "auth_db_name";
$db['authentication']['dbdriver'] = "mysql";

Then in the constructor of the ion_auth_model.php do this:

$this->db = $this->load->database('authentication', TRUE);

And it should just work after that.

Ben Edmunds
  • 888
  • 4
  • 6