primero que nada no entendi a que hacias referencia con "pojo" si tiene que usar muchas base de datos creo que el problema esta ahí deberias tener una sola con miles de tabla de ultima. Pero bueno eso es otro tema. Yo tuve que usar una db para un sistema que hice y que luego me pidieron que extrajera datos de un oscommerce, tras lidiar un poco lo logre de la siguiente manera:
mi modelo que apunta a la db oscommerce:
Código PHP:
Ver originalclass Productos_model extends MY_Model
{
private $db2 = null;
function __construct()
{
parent::__construct();
$this->tabla = 'products';
$this->primary_key = 'products_id';
$this->db2 = $this->load->database('wp',TRUE);
}
public function todos($categoria_id = null){
$this->db2->select(" p.products_id, pd.products_name,p.manufacturers_id, p.products_price, p.products_tax_class_id");
$this->db2->join('specials s',"p.products_id = s.products_id",'left'); $this->db2->join('products_to_categories p2c',"p.products_id = p2c.products_id",'left'); $this->db2->join('products_description pd',"pd.products_id = p2c.products_id",'left'); $this->db2->join('manufacturers m',"p.manufacturers_id = m.manufacturers_id",'left'); $this->db2->join('products_to_stores ps',"ps.products_id = p.products_id",'left'); $this->db2->where('ps.stores_id','1');
$this->db2->where('p.products_status','1');
if($categoria_id){
$this->db2->where('p2c.categories_id',$categoria_id);
}
$query = $this->db2->get($this->tabla.' p');
return $query->result_array();
}
public function buscar_producto($id){
$this->db2->select(" p.products_id, pd.products_name,p.manufacturers_id, p.products_price, p.products_tax_class_id,t.tax_rate,s.specials_new_products_price");
$this->db2->join('specials s',"p.products_id = s.products_id",'left'); $this->db2->join('products_to_categories p2c',"p.products_id = p2c.products_id",'left'); $this->db2->join('products_description pd',"pd.products_id = p2c.products_id",'left'); $this->db2->join('manufacturers m',"p.manufacturers_id = m.manufacturers_id",'left'); $this->db2->join('products_to_stores ps',"ps.products_id = p.products_id",'left'); $this->db2->join('tax_rates t',"t.tax_rates_id = p.products_tax_class_id",'left'); $this->db2->where('ps.stores_id','1');
$this->db2->where('p.products_status','1');
$this->db2->where('p.products_id',$id);
$query = $this->db2->get($this->tabla.' p');
$result = $query->result_array();
return $result[0];
}
}
modelo que apunta a la db de mi sistema:
Código PHP:
Ver original<?php
/**
* Creado por Onírico Sistemas.
* Usuario: onirico
* Fecha: 22/04/13
* Hora: 14:27
*
*/
class Empresas_model extends MY_Model
{
function __construct()
{
parent::__construct();
$this->tabla = 'empresas';
$this->primary_key = 'empresa_id';
}
public function todos($order_by = 'empresa_id', $order = 'desc',$like = null){
$this->db->order_by($order_by,$order);
if($like){
foreach($like as $clave => $valor){
$this->db->like($clave,$valor,'after');
}
foreach($array as $key){
if($order == 'des'){
$order = 'desc';
}
$this->db->order_by($order_by,$order);
}
}
else{
if($order == 'des'){
$order = 'desc';
}
$this->db->order_by($order_by,$order);
}
$query = $this->db->get($this->tabla);
return $query->result_array();
}
public function empresa_usuario($id){
$this->db->select('e.*,p.nombre AS pais');
$this->db->join('pais p','p.id = e.pais'); $this->db->where('empresa_id',$id);
$query = $this->db->get($this->tabla.' e');
return $query->result_array();
}
}
archivo de configuracion de las base de datos:
Código PHP:
Ver originalcaching
| ['cachedir'] The path to the folder where cache files should be stored
| ['char_set'] The character set used in communicating with the database
| ['dbcollat'] The character collation used in communicating with the database
| NOTE
: For MySQL and MySQLi databases
, this setting is only used
| as a backup
if your server is running PHP
< 5
.2
.3 or
MySQL < 5
.0
.7
| (and in table creation queries made with DB Forge).
| can make your site vulnerable to SQL injection if you are using a
| multi-byte character set and are running versions lower than these.
| Sites using Latin-1 or UTF-8 database character set and collation are unaffected.
| ['swap_pre'] A default table prefix that should be swapped with the dbprefix
| ['autoinit'] Whether or not to automatically initialize the database.
| ['stricton'] TRUE/FALSE - forces 'Strict Mode' connections
| - good for ensuring strict SQL while developing
|
| The $active_group variable lets you choose which connection group to
| make active. By default there is only one group (the 'default' group).
|
| The $active_record variables lets you determine whether or not to load
| the active record class
*/
$active_group = 'default';
$active_record = TRUE;
if(ENVIRONMENT == 'development'){
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'root';
$db['default']['password'] = '';
$db['default']['database'] = 'duchamania';
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = '';
//conexion a la otra base de datos
$db['wp']['hostname'] = 'localhost';
$db['wp']['username'] = 'root';
$db['wp']['password'] = '';
$db['wp']['database'] = 'mundoba_osc2';
$db['wp']['dbdriver'] = 'mysql';
$db['wp']['dbprefix'] = '';
$db['wp']['pconnect'] = FALSE;
$db['wp']['db_debug'] = TRUE;
$db['wp']['cache_on'] = FALSE;
$db['wp']['cachedir'] = '';
$db['wp']['char_set'] = 'utf8';
$db['wp']['dbcollat'] = 'utf8_general_ci';
$db['wp']['swap_pre'] = '';
$db['wp']['autoinit'] = TRUE;
$db['wp']['stricton'] = FALSE;
}
else{
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'xxx_78';
$db['default']['password'] = 'xxxx';
$db['default']['database'] = 'mundoba_presup';
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = '';
}
$db['default']['pconnect'] = FALSE;
$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;
y despues en el controlador llamos los modelos asi:
Código PHP:
Ver originalclass Presupuestos extends CI_Controller
{
private $session_group;
public function __construct()
{
parent::__construct();
//aca instancio los modelos del osccomerce
$this->load->model('Categorias_model','categorias');
$this->load->model('Subcategoria_model','subcategorias');
$this->load->model('Productos_model','productos');
// van mis modelos
$this->load->model('Usuarios_model','usuarios');
$this->load->model('Numeros_model','numeros');
$this->load->model('Clientes_model','clientes');
$this->load->model('Clientes_Direcciones_model','clientes_direcciones');
$this->load->model('Presupuesto_model','presupuesto');
$this->load->model('Pedidos_model','pedidos');
$this->load->model('Facturas_model','facturas');
$this->load->model('Item_model','items');
$this->load->model('Empresas_model','empresas');
$this->load->model('Paises_model','pais');
lo que hace $this->load->model('Nombre_modelo'). es buscar el modelo por el nombre que pones en los parentesis en la carpeta model e instanciarlo para poder usarlo.
Yo en tu caso creacia x cantidad de conexiones en el archivo de configuracion y en cada modelo las vas llamando cuando sea necesario.
Saludos