3

I have a problem to connect to remote database by DSN using ODBC driver in CodeIgniter 3.1.10 as mention above. The DSN has been created in ODBC Data Source Administrator. The problem occurred when I want to update the system from CodeIgniter 2.2.3 to 3.1.10.

It actually work on CodeIgniter 2.2.3 with code below:

$db['default']['hostname'] = "myDSN";
$db['default']['username'] = '';
$db['default']['password'] = '';
$db['default']['database'] = 'myDatabase';
$db['default']['dbdriver'] = 'odbc';
$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;

But it display error below:

Database driver is not currently loaded

when I tried with the same settings on CodeIgniter 3.1.10 as code below:

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

However in CodeIgniter 3.1.10, the connection is successful when I manually connect to database using code below:

$dbconn=odbc_connect("myDSN", "", "");

if(!$dbconn)
{
    die("Could not connect Adaptive Server Anywhere: ".odbc_errormsg(). odbc_error());
} else {
    echo "connection success";
}

So, since it can connect when using manual code, can someone guide me how to connect successfully by using the database code in CodeIgniter 3.1.10?

Shafiq Khalid
  • 81
  • 1
  • 2

1 Answers1

1

After quite a bit of research on this - I believe the issue is not with the ODBC element but the fact you've not autoloaded the database library. The error doesn't relate to ODBC but as I found here: Codeigniter: Database driver is not currently loaded is because I don't believe you've autoloaded the database.

Antony
  • 3,875
  • 30
  • 32