Ionize CMS - module with a second database

I am new to the world of Ionize CMS and I need your help. Is it possible to create a module to work with a second database? The idea is to create two types of website:

  • one as database management (with its own database db1 ) where content is added / modified and removed. This site's database will serve the content for the second type of website.

  • the second type (with its own db2 database ) will display content from the first site's db1 database (based on specific configuration, doesn't matter). For this website, I want to create a module with the main purpose to get data from db1

Based on the documentation, I saw how it is possible to access the parent database module (CMS db2 database), but now not use tables from another database (like db1)

This kind of website will be installed on the same or different hosting.

Any help would be greatly appreciated

+3


source to share


1 answer


Since Ionize is a CodeIgniter based CMS, you can use more database connections. To do what you need on the second type of website, you must define your database configurations in\application\config\database.php

Configuration example:

$db['db1']['hostname'] = '';
$db['db1']['username'] = '';
$db['db1']['password'] = '';
$db['db1']['database'] = '';
$db['db1']['dbdriver'] = 'mysqli';
$db['db1']['dbprefix'] = '';
$db['db1']['swap_pre'] = '';
$db['db1']['pconnect'] = FALSE;
$db['db1']['db_debug'] = FALSE;
$db['db1']['cache_on'] = FALSE;
$db['db1']['cachedir'] = '';
$db['db1']['char_set'] = 'utf8';
$db['db1']['dbcollat'] = 'utf8_unicode_ci';

$db['db2']['hostname'] = '';
$db['db2']['username'] = '';
$db['db2']['password'] = '';
$db['db2']['database'] = '';
$db['db2']['dbdriver'] = 'mysqli';
$db['db2']['dbprefix'] = '';
$db['db2']['swap_pre'] = '';
$db['db2']['pconnect'] = FALSE;
$db['db2']['db_debug'] = FALSE;
$db['db2']['cache_on'] = FALSE;
$db['db2']['cachedir'] = '';
$db['db2']['char_set'] = 'utf8';
$db['db2']['dbcollat'] = 'utf8_unicode_ci';

      

where db1 will be the default database used by Ionizem and db2 will be the database from type 1 website . After that, you can make queries to db2 using something like this:



$this->remote_db = $this->load->database('db2', TRUE);
$query = $this->remote_db ->get('table_from_website_1');

      

With this aproach don't use persistent connection ( ['pconnect'] = FALSE;

)

For me this config works like a charm

+3


source







All Articles