I've a website currently running in CI and it has a user table. I'm making a WordPress website and need it to use the user table of the CI database for users to login in WordPress. How can I use only that table of different database? Both DBs are on same server. Also I have to differentiate between admin and normal users, as admins can enter the dashboard. I've tried this plugin but as soon as I activate this plugin my login page stops working and displays a 500 server error.
I've a website currently running in CI and it has a user table. I'm making a WordPress website and need it to use the user table of the CI database for users to login in WordPress. How can I use only that table of different database? Both DBs are on same server. Also I have to differentiate between admin and normal users, as admins can enter the dashboard. I've tried this plugin but as soon as I activate this plugin my login page stops working and displays a 500 server error.
It might work to use a view as essentially a table alias, by doing the something like the following with the WordPress instance mysql database
DROP TABLE wp_users
CREATE VIEW wp_users AS SELECT * FROM CI.users;
However
wp_usermeta
table to properly signify admins.You don't need a plugin to make multiple db connections in CI. Just do this:
This is your default CI database config
$db['default']['hostname'] = 'DB_HOST';
$db['default']['username'] = 'DB_USER';
$db['default']['password'] = 'DB_PASSWORD';
$db['default']['database'] = 'DB_NAME';
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = '';
$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;
Duplicate that chunk of code, renaming the $db['default']
with something like $db['secondary']
$db['secondary']['hostname'] = 'SECONDARY_DB_HOST';
$db['secondary']['username'] = 'SECONDARY_DB_USER';
$db['secondary']['password'] = 'SECONDARY_DB_PASSWORD';
$db['secondary']['database'] = 'SECONDARY_DB_NAME';
$db['secondary']['dbdriver'] = 'mysql';
$db['secondary']['dbprefix'] = '';
$db['secondary']['pconnect'] = TRUE;
$db['secondary']['db_debug'] = TRUE;
$db['secondary']['cache_on'] = FALSE;
$db['secondary']['cachedir'] = '';
$db['secondary']['char_set'] = 'utf8';
$db['secondary']['dbcollat'] = 'utf8_general_ci';
$db['secondary']['swap_pre'] = '';
$db['secondary']['autoinit'] = TRUE;
$db['secondary']['stricton'] = FALSE;
function getWordpressUsers() {
$secondaryDb = $this->load->database('secondary', TRUE);
$query = $secondaryDb->select('user_email, display_name')->get('wp_users');
var_dump($query);
}
For more info about it, check this out: https://codeigniter/user_guide/database/connecting.html
It's not possible in Wordpress to have shared users between 2 separates installations on 2 separated databases.
It could be possible just by hardcoding:
but mentioned solution is not recommended of course, because it's not updateproof.