CodeIgniter Forums

Full Version: system check the registered email database, and log in to the related DB
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello, how do I make the following change in codeigniter, it's possible?

when logging into the system check the registered email database, and log in to the related database, for example:

User: teste@teste.com
Database: xyz

User: teste2@teste.com
database: abc

after login, this will be the user session database.


I tried in many bad ways it does not work

my function of verification email x database



Code:
function get_base_email($email)
{
   $CI = & get_instance();
   $CI->db->where('email', $email);

   return $CI->db->get('tblusuariobanco')->row()->banco;
}

my database.php


Code:
$db['xyz'] = [
   'dsn'          => '', // Not Supported
   'hostname'     => APP_DB_HOSTNAME,
   'username'     => APP_DB_USERNAME,
   'password'     => APP_DB_PASSWORD,
   'database'     => 'gestor',
   'dbdriver'     => defined('APP_DB_DRIVER') ? APP_DB_DRIVER : 'mysqli',
   'dbprefix'     => '', // Not Supported
   'pconnect'     => false,
   'db_debug'     => (ENVIRONMENT !== 'production'),
   'cache_on'     => false,
   'cachedir'     => '',
   'char_set'     => 'utf8',
   'dbcollat'     => 'utf8_general_ci',
   'swap_pre'     => '',
   'encrypt'      => $db_encrypt,
   'compress'     => false,
   'stricton'     => false,
   'failover'     => [],
   'save_queries' => true,
];

$db['abc'] = [
   'dsn'          => '', // Not Supported
   'hostname'     => APP_DB_HOSTNAME,
   'username'     => APP_DB_USERNAME,
   'password'     => APP_DB_PASSWORD,
   'database'     => 'xxx',
   'dbdriver'     => defined('APP_DB_DRIVER') ? APP_DB_DRIVER : 'mysqli',
   'dbprefix'     => '', // Not Supported
   'pconnect'     => false,
   'db_debug'     => (ENVIRONMENT !== 'production'),
   'cache_on'     => false,
   'cachedir'     => '',
   'char_set'     => 'utf8',
   'dbcollat'     => 'utf8_general_ci',
   'swap_pre'     => '',
   'encrypt'      => $db_encrypt,
   'compress'     => false,
   'stricton'     => false,
   'failover'     => [],
   'save_queries' => true,
];

trying to set the database when signing in

Code:
$active_group = get_base_email($email);
@samuca.ti,

Are you sure that both database signons are working? Did you confirm it?
Yes, they are, and my function returns the database correctly.
Just do not know how to do the reload of the database, for the selected.
@samuca.ti,

Maybe this documentation will help you https://www.codeigniter.com/userguide3/d...-databases .
already tried,
can not update the $ db variable?

I'm learning codeigniter, sorry.

after login:
I'm trying

class Authentication extends CRM_Controller
{
...
...

runkit_constant_redefine ('APP_DB', get_base_email($email));

$this->db->close();
$this->db->db_select(APP_DB);
$this->db->reconnect();
@samuca.ti,

What do you mean by can not update the $db variable?