• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
HELP!!! 2 database in Codeigniter

#1
[eluser]hrg.vincent[/eluser]
I've problem in getting data from second database. First is used mysql and another is odbc. My default database is mysql.

=== application/config/custom.php ===
Code:
// get special condition
$isDb = isset($_GET['ndb']) && $_GET['ndb'] == 'y' ? false : true;

$config['doCron'] = true;

if($isDb){
$config['dbconn'] = @odbc_connect(MY_DATABASE_HOST, MY_DATABASE_NAME, MY_DATABASE_PSWD) or showDBError(MY_DB_ERROR_HEAD, MY_DB_ERROR_MSG);
}
else{
$config['dbconn'] = false;
}

function showDBError($heading, $message){
require_once APPPATH.'errors/error_db.php';
exit();
}

=== Controller ===
Code:
$data['company'] = $this->Data_m->getCompany();

=== Data Model ===
Code:
class Data_m extends CI_Model
{
function __construct()
{
  parent::__construct();
  $this->dbconn = $this->config->config['dbconn'];
  $this->NOW = date(TSTAMPT);
}

function getCompany()
{
  $sql = "SELECT company_id, company_name FROM dev.company";  
  $result = odbc_exec($this->dbconn, $sql);
  
  while (odbc_fetch_row($result))
  {
   foreach($result->result_array() as $row) {
    $return[$row['company_id']] = $row['company_name'];
   }
  }
  
  return $return;  
}
}

=== View ===
Code:
<?php echo form_dropdown('company', $company) ?>

Note: All data from mysql is working, only odbc is not working. Pls help.

#2
[eluser]DuyK-DCT[/eluser]
Try to look a topic in stackoverflow http://stackoverflow.com/questions/63429...-databases


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.