CodeIgniter Forums
Problem using two different database - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: Problem using two different database (/showthread.php?tid=70867)



Problem using two different database - villa.eduardobarros - 06-11-2018

Hello, people of the forum.
All right?

I'm working with two databases, MySQL as primary and Progress as secondary bank via ODBC ...
The following is the code for the connections:

database.php

PHP Code:
$active_group 'default';
$query_builder TRUE;
$active_record TRUE;

$db['default'] = array(
    
'dsn'    => '',
    
'hostname' => 'Xxxx',
    
'username' => 'Xxxx',
    
'password' => 'Xxxx!',
    
'database' => 'Xxxx',
    
'dbdriver' => 'mysqli',
    
'dbprefix' => '',
    
'pconnect' => FALSE,
    
'db_debug' => (ENVIRONMENT !== 'production'),
    
'cache_on' => FALSE,
    
'cachedir' => '',
    
'char_set' => 'utf8',
    
'dbcollat' => 'utf8_general_ci',
    
'swap_pre' => '',
    
'encrypt' => FALSE,
    
'compress' => FALSE,
    
'stricton' => FALSE,
    
'failover' => array(),
    
'save_queries' => TRUE
);


$db['Zzzzzzzzz'] = array(
    
'dsn'       => '',
    
'hostname' => 'Zzzz',
    
'username' => 'Zzzz',
    
'password' => 'Zzzz',
    
'database' => 'Zzzz',
    
'dbdriver' => 'odbc',
    
'dbprefix' => '',
    
'pconnect' => FALSE,
    
'db_debug' => (ENVIRONMENT !== 'production'),
    
'cache_on' => FALSE,
    
'cachedir' => '',
    
'char_set' => 'utf8',
    
'dbcollat' => 'utf8_general_ci',
    
'swap_pre' => '',
    
'encrypt' => FALSE,
    
'compress' => FALSE,
    
'stricton' => FALSE,
    
'failover' => array(),
    
'save_queries' => TRUE
); 


The default database is working normally, but when I try to access the database via ODBC with activerecord the following error:
Code:
Fatal error: Call to undefined method CI_DB_odbc_driver::get() in C:\xampp\htdocs\novo\application\modules\test\models\Md_test.php on line 15

md_test .php
PHP Code:
class Md_test extends CI_Model {

    function 
__construct(){
        
parent::__construct();
        
$this->test$this->load->database('Zzzzzzzzz'TRUE);
    }

 
   
    function buscaPedidos
($dt)
    {
        return 
$this->test->get('Zzzzz'); // line 15
    
}
 
   


Can anybody help me?


RE: Problem using two different database - ciadmin - 06-11-2018

The query builder cannot be used with the ODBC driver. See https://forum.codeigniter.com/thread-65803.html


RE: Problem using two different database - villa.eduardobarros - 06-12-2018

I was able to mount a query and return an array, but it does not show me the name of the columns (key)...

PHP Code:
$data['test'] = $this->md_test->buscaPedidoAtual($dt);
$row $data['test']->result_array();

echo 
'<pre>';
var_dump($row);
echo 
'</pre>'

Result:
Code:
array(49) {
 ["100"]=>
 string(3) "100"
 ["1"]=>
 string(1) "1"
 ["0131826"]=>
 string(7) "0131826"
 ...
 ...
...
...