Welcome Guest, Not a member yet? Register   Sign In
How to connect to a database via ODBC on Windows
#1

[eluser]Jonathon Hill[/eluser]
Hello everyone,

There seems to be a lack of clear examples on how to get ODBC working in CI, at least clear for those unfamiliar with ODBC! Here's how I did it:

database.php config file:

Code:
$db['mydb']['hostname'] = "dsn=mysystemdsn;";  // notice the lower case and semicolon
$db['mydb']['username'] = "username";
$db['mydb']['password'] = "password";
$db['mydb']['database'] = "";
$db['mydb']['dbdriver'] = "odbc";
$db['mydb']['dbprefix'] = "";
$db['mydb']['pconnect'] = TRUE;
$db['mydb']['db_debug'] = TRUE;
$db['mydb']['cache_on'] = FALSE;
$db['mydb']['cachedir'] = "";
$db['mydb']['char_set'] = "";
$db['mydb']['dbcollat'] = "";

mysystemdsn is the name of the system dsn you set up in the Windows XP control panel (Administrative Tools -> Data Sources (ODBC)). Here's a tutorial for that.


odbc_driver.php:

There's a bug in the ODBC driver file (I'm using CI 1.5.3), so replace the function CI_DB_odbc_driver():

Code:
function CI_DB_odbc_driver($params)
{
    parent::CI_DB($params);
    $this->_random_keyword = ' RND('.time().')'; // database specific random keyword
}




Theme © iAndrew 2016 - Forum software by © MyBB