Welcome Guest, Not a member yet? Register   Sign In
ODBC Connection Help
#1

[eluser]hrg.vincent[/eluser]
Hi all, please help to check, anything wrong from my code in below. I'm using ODBC connection but fails to get data into dropdownlist.

I keep getting error "Undefined variable: company_list". I trying mysql and it's work. So I thinking that is something wrong from the ODBC code.

Code:
// Controller

public function getCompanyData()
{
$this->load->model('Company_m');
$data['company_list'] = $this->Company_m->getCompany();
}

Code:
// Model -->Company_m

function __construct()
{
// Call the Model constructor
parent::__construct();
$this->GEMINI = @odbc_connect(MY_DATABASE_HOST, MY_DATABASE_NAME, MY_DATABASE_PSWD);
}

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

Code:
// View

<?php echo form_dropdown('company_list', $company_list); ?>
#2

[eluser]pickupman[/eluser]
You are calling:
Code:
$result->result_array()

However, you are not using the ActiveRecord class, but straight PHP. That causes the result_array() to not be an available method. You may want to try out using [url="http://ellislab.com/codeigniter/user-guide/database/configuration.html"]CI's odbc driver[/url]. It will connect in the same way you are trying to in your constructor, but give you access to the CI ActiveRecord methods.

If you don't switch to that option, you will need to iterate the result using straight PHP which defeats some of the purpose of using CI.




Theme © iAndrew 2016 - Forum software by © MyBB